memory-journal-mcp 8.0.1 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +278 -353
- package/dist/audit/audit-logger.d.ts +89 -0
- package/dist/audit/audit-logger.d.ts.map +1 -0
- package/dist/audit/audit-resource.d.ts +28 -0
- package/dist/audit/audit-resource.d.ts.map +1 -0
- package/dist/audit/index.d.ts +12 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/interceptor.d.ts +44 -0
- package/dist/audit/interceptor.d.ts.map +1 -0
- package/dist/audit/types.d.ts +68 -0
- package/dist/audit/types.d.ts.map +1 -0
- package/dist/auth/auth-context.d.ts +42 -0
- package/dist/auth/auth-context.d.ts.map +1 -0
- package/dist/auth/authorization-server-discovery.d.ts +90 -0
- package/dist/auth/authorization-server-discovery.d.ts.map +1 -0
- package/dist/auth/errors.d.ts +90 -0
- package/dist/auth/errors.d.ts.map +1 -0
- package/dist/auth/index.d.ts +16 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/middleware.d.ts +77 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/oauth-resource-server.d.ts +73 -0
- package/dist/auth/oauth-resource-server.d.ts.map +1 -0
- package/dist/auth/scope-map.d.ts +14 -0
- package/dist/auth/scope-map.d.ts.map +1 -0
- package/dist/auth/scopes.d.ts +112 -0
- package/dist/auth/scopes.d.ts.map +1 -0
- package/dist/auth/token-validator.d.ts +64 -0
- package/dist/auth/token-validator.d.ts.map +1 -0
- package/dist/auth/transport-agnostic.d.ts +47 -0
- package/dist/auth/transport-agnostic.d.ts.map +1 -0
- package/dist/auth/types.d.ts +256 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/validation.d.ts +15 -0
- package/dist/auth/validation.d.ts.map +1 -0
- package/dist/chunk-4FZCHFB5.js +216 -0
- package/dist/chunk-D2FY6XS5.js +313 -0
- package/dist/chunk-E6IQP6PE.js +252 -0
- package/dist/chunk-FZLB6NAV.js +746 -0
- package/dist/chunk-LE6ZWUPK.js +2667 -0
- package/dist/chunk-SGJU2DHU.js +2102 -0
- package/dist/chunk-T7SROBBV.js +34066 -0
- package/dist/chunk-Y6MMKR2Z.js +3766 -0
- package/dist/cli/commands/admin.d.ts +123 -0
- package/dist/cli/commands/admin.d.ts.map +1 -0
- package/dist/cli/commands/analytics.d.ts +21 -0
- package/dist/cli/commands/analytics.d.ts.map +1 -0
- package/dist/cli/commands/entry-payload.d.ts +38 -0
- package/dist/cli/commands/entry-payload.d.ts.map +1 -0
- package/dist/cli/commands/entry.d.ts +130 -0
- package/dist/cli/commands/entry.d.ts.map +1 -0
- package/dist/cli/commands/exec.d.ts +31 -0
- package/dist/cli/commands/exec.d.ts.map +1 -0
- package/dist/cli/commands/io.d.ts +76 -0
- package/dist/cli/commands/io.d.ts.map +1 -0
- package/dist/cli/commands/project.d.ts +6 -0
- package/dist/cli/commands/project.d.ts.map +1 -0
- package/dist/cli/commands/search.d.ts +30 -0
- package/dist/cli/commands/search.d.ts.map +1 -0
- package/dist/cli/commands/serve.d.ts +84 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/visualize.d.ts +20 -0
- package/dist/cli/commands/visualize.d.ts.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +9 -0
- package/dist/cli/option-groups.d.ts +18 -0
- package/dist/cli/option-groups.d.ts.map +1 -0
- package/dist/cli/program.d.ts +7 -0
- package/dist/cli/program.d.ts.map +1 -0
- package/dist/cli/schemas.d.ts +648 -0
- package/dist/cli/schemas.d.ts.map +1 -0
- package/dist/cli/server-options-builder.d.ts +13 -0
- package/dist/cli/server-options-builder.d.ts.map +1 -0
- package/dist/cli.js +9 -433
- package/dist/codemode/api/git-api.d.ts +9 -0
- package/dist/codemode/api/git-api.d.ts.map +1 -0
- package/dist/codemode/api/group-factory.d.ts +30 -0
- package/dist/codemode/api/group-factory.d.ts.map +1 -0
- package/dist/codemode/api/index.d.ts +10 -0
- package/dist/codemode/api/index.d.ts.map +1 -0
- package/dist/codemode/api/journal-api.d.ts +39 -0
- package/dist/codemode/api/journal-api.d.ts.map +1 -0
- package/dist/codemode/api/key-normalizer.d.ts +8 -0
- package/dist/codemode/api/key-normalizer.d.ts.map +1 -0
- package/dist/codemode/api/param-normalizer.d.ts +15 -0
- package/dist/codemode/api/param-normalizer.d.ts.map +1 -0
- package/dist/codemode/api/project-registry-ops.d.ts +26 -0
- package/dist/codemode/api/project-registry-ops.d.ts.map +1 -0
- package/dist/codemode/api/sandbox-bindings.d.ts +25 -0
- package/dist/codemode/api/sandbox-bindings.d.ts.map +1 -0
- package/dist/codemode/api/types.d.ts +21 -0
- package/dist/codemode/api/types.d.ts.map +1 -0
- package/dist/codemode/api-constants.d.ts +6 -0
- package/dist/codemode/api-constants.d.ts.map +1 -0
- package/dist/codemode/auto-return.d.ts +25 -0
- package/dist/codemode/auto-return.d.ts.map +1 -0
- package/dist/codemode/constants/examples-and-params.d.ts +31 -0
- package/dist/codemode/constants/examples-and-params.d.ts.map +1 -0
- package/dist/codemode/constants/method-aliases.d.ts +8 -0
- package/dist/codemode/constants/method-aliases.d.ts.map +1 -0
- package/dist/codemode/index.d.ts +12 -0
- package/dist/codemode/index.d.ts.map +1 -0
- package/dist/codemode/normalizers/domain-tool-interceptions.d.ts +6 -0
- package/dist/codemode/normalizers/domain-tool-interceptions.d.ts.map +1 -0
- package/dist/codemode/normalizers/entry-and-search-interceptions.d.ts +6 -0
- package/dist/codemode/normalizers/entry-and-search-interceptions.d.ts.map +1 -0
- package/dist/codemode/normalizers/generic-interceptions.d.ts +6 -0
- package/dist/codemode/normalizers/generic-interceptions.d.ts.map +1 -0
- package/dist/codemode/normalizers/github-and-backup-interceptions.d.ts +6 -0
- package/dist/codemode/normalizers/github-and-backup-interceptions.d.ts.map +1 -0
- package/dist/codemode/normalizers/shared-utils.d.ts +31 -0
- package/dist/codemode/normalizers/shared-utils.d.ts.map +1 -0
- package/dist/codemode/param-normalizer.d.ts +11 -0
- package/dist/codemode/param-normalizer.d.ts.map +1 -0
- package/dist/codemode/proxy-helpers.d.ts +34 -0
- package/dist/codemode/proxy-helpers.d.ts.map +1 -0
- package/dist/codemode/proxy-namespaces.d.ts +30 -0
- package/dist/codemode/proxy-namespaces.d.ts.map +1 -0
- package/dist/codemode/sandbox-factory.d.ts +52 -0
- package/dist/codemode/sandbox-factory.d.ts.map +1 -0
- package/dist/codemode/security.d.ts +54 -0
- package/dist/codemode/security.d.ts.map +1 -0
- package/dist/codemode/type-generator.d.ts +11 -0
- package/dist/codemode/type-generator.d.ts.map +1 -0
- package/dist/codemode/types.d.ts +165 -0
- package/dist/codemode/types.d.ts.map +1 -0
- package/dist/codemode/worker/mj-shim-domains.d.ts +15 -0
- package/dist/codemode/worker/mj-shim-domains.d.ts.map +1 -0
- package/dist/codemode/worker/mj-shim-proxy.d.ts +18 -0
- package/dist/codemode/worker/mj-shim-proxy.d.ts.map +1 -0
- package/dist/codemode/worker/namespace-shims.d.ts +32 -0
- package/dist/codemode/worker/namespace-shims.d.ts.map +1 -0
- package/dist/codemode/worker/node-shims.d.ts +65 -0
- package/dist/codemode/worker/node-shims.d.ts.map +1 -0
- package/dist/codemode/worker/prototype-hardening.d.ts +18 -0
- package/dist/codemode/worker/prototype-hardening.d.ts.map +1 -0
- package/dist/codemode/worker/result-compactor.d.ts +20 -0
- package/dist/codemode/worker/result-compactor.d.ts.map +1 -0
- package/dist/codemode/worker/sandbox-globals.d.ts +19 -0
- package/dist/codemode/worker/sandbox-globals.d.ts.map +1 -0
- package/dist/codemode/worker-api-proxy.d.ts +12 -0
- package/dist/codemode/worker-api-proxy.d.ts.map +1 -0
- package/dist/codemode/worker-result-proxy.d.ts +12 -0
- package/dist/codemode/worker-result-proxy.d.ts.map +1 -0
- package/dist/codemode/worker-sandbox.d.ts +58 -0
- package/dist/codemode/worker-sandbox.d.ts.map +1 -0
- package/dist/codemode/worker-script.d.ts +9 -0
- package/dist/codemode/worker-script.d.ts.map +1 -0
- package/dist/constants/icons.d.ts +58 -0
- package/dist/constants/icons.d.ts.map +1 -0
- package/dist/constants/instructions/admin.d.ts +2 -0
- package/dist/constants/instructions/admin.d.ts.map +1 -0
- package/dist/constants/instructions/analytics.d.ts +2 -0
- package/dist/constants/instructions/analytics.d.ts.map +1 -0
- package/dist/constants/instructions/backup.d.ts +2 -0
- package/dist/constants/instructions/backup.d.ts.map +1 -0
- package/dist/constants/instructions/base.d.ts +3 -0
- package/dist/constants/instructions/base.d.ts.map +1 -0
- package/dist/constants/instructions/codemode.d.ts +2 -0
- package/dist/constants/instructions/codemode.d.ts.map +1 -0
- package/dist/constants/instructions/core.d.ts +2 -0
- package/dist/constants/instructions/core.d.ts.map +1 -0
- package/dist/constants/instructions/git.d.ts +2 -0
- package/dist/constants/instructions/git.d.ts.map +1 -0
- package/dist/constants/instructions/github.d.ts +2 -0
- package/dist/constants/instructions/github.d.ts.map +1 -0
- package/dist/constants/instructions/gotchas.d.ts +2 -0
- package/dist/constants/instructions/gotchas.d.ts.map +1 -0
- package/dist/constants/instructions/io.d.ts +2 -0
- package/dist/constants/instructions/io.d.ts.map +1 -0
- package/dist/constants/instructions/relationships.d.ts +2 -0
- package/dist/constants/instructions/relationships.d.ts.map +1 -0
- package/dist/constants/instructions/search.d.ts +2 -0
- package/dist/constants/instructions/search.d.ts.map +1 -0
- package/dist/constants/instructions/team.d.ts +2 -0
- package/dist/constants/instructions/team.d.ts.map +1 -0
- package/dist/constants/instructions/templates.d.ts +2 -0
- package/dist/constants/instructions/templates.d.ts.map +1 -0
- package/dist/constants/server-instructions.d.ts +64 -0
- package/dist/constants/server-instructions.d.ts.map +1 -0
- package/dist/database/adapter-factory.d.ts +9 -0
- package/dist/database/adapter-factory.d.ts.map +1 -0
- package/dist/database/core/DatabaseAdapterProxy.d.ts +5 -0
- package/dist/database/core/DatabaseAdapterProxy.d.ts.map +1 -0
- package/dist/database/core/interfaces.d.ts +455 -0
- package/dist/database/core/interfaces.d.ts.map +1 -0
- package/dist/database/migrations/001-init.d.ts +3 -0
- package/dist/database/migrations/001-init.d.ts.map +1 -0
- package/dist/database/migrations/002-add-significance-and-context.d.ts +3 -0
- package/dist/database/migrations/002-add-significance-and-context.d.ts.map +1 -0
- package/dist/database/migrations/003-add-deleted-and-archived.d.ts +3 -0
- package/dist/database/migrations/003-add-deleted-and-archived.d.ts.map +1 -0
- package/dist/database/migrations/004-add-github-and-workflow-integration.d.ts +3 -0
- package/dist/database/migrations/004-add-github-and-workflow-integration.d.ts.map +1 -0
- package/dist/database/migrations/005-add-entry-revisions.d.ts +3 -0
- package/dist/database/migrations/005-add-entry-revisions.d.ts.map +1 -0
- package/dist/database/migrations/006-add-analytics-snapshots.d.ts +3 -0
- package/dist/database/migrations/006-add-analytics-snapshots.d.ts.map +1 -0
- package/dist/database/migrations/007-add-team-author.d.ts +3 -0
- package/dist/database/migrations/007-add-team-author.d.ts.map +1 -0
- package/dist/database/migrations/008-add-team-members.d.ts +3 -0
- package/dist/database/migrations/008-add-team-members.d.ts.map +1 -0
- package/dist/database/migrations/009-add-entry-version.d.ts +3 -0
- package/dist/database/migrations/009-add-entry-version.d.ts.map +1 -0
- package/dist/database/migrations/010-add-author-aliases.d.ts +3 -0
- package/dist/database/migrations/010-add-author-aliases.d.ts.map +1 -0
- package/dist/database/migrations/011-add-workspace-id.d.ts +3 -0
- package/dist/database/migrations/011-add-workspace-id.d.ts.map +1 -0
- package/dist/database/migrations/012-add-trust-and-anchors.d.ts +3 -0
- package/dist/database/migrations/012-add-trust-and-anchors.d.ts.map +1 -0
- package/dist/database/migrations/013-add-session-id.d.ts +3 -0
- package/dist/database/migrations/013-add-session-id.d.ts.map +1 -0
- package/dist/database/migrations/migration-list.d.ts +3 -0
- package/dist/database/migrations/migration-list.d.ts.map +1 -0
- package/dist/database/migrations/migration-manager.d.ts +14 -0
- package/dist/database/migrations/migration-manager.d.ts.map +1 -0
- package/dist/database/migrations/migration.d.ts +23 -0
- package/dist/database/migrations/migration.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/adapter-delegates.d.ts +161 -0
- package/dist/database/sqlite-adapter/adapter-delegates.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/aliases.d.ts +14 -0
- package/dist/database/sqlite-adapter/aliases.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/backup.d.ts +27 -0
- package/dist/database/sqlite-adapter/backup.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/database-adapter.d.ts +192 -0
- package/dist/database/sqlite-adapter/database-adapter.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/anchors.d.ts +9 -0
- package/dist/database/sqlite-adapter/entries/anchors.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/crud-read.d.ts +16 -0
- package/dist/database/sqlite-adapter/entries/crud-read.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/crud-write.d.ts +62 -0
- package/dist/database/sqlite-adapter/entries/crud-write.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/crud.d.ts +4 -0
- package/dist/database/sqlite-adapter/entries/crud.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/digest.d.ts +60 -0
- package/dist/database/sqlite-adapter/entries/digest.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/fuzzy-matcher.d.ts +27 -0
- package/dist/database/sqlite-adapter/entries/fuzzy-matcher.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/importance.d.ts +38 -0
- package/dist/database/sqlite-adapter/entries/importance.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/index.d.ts +186 -0
- package/dist/database/sqlite-adapter/entries/index.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/revisions.d.ts +16 -0
- package/dist/database/sqlite-adapter/entries/revisions.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/search/cursor.d.ts +15 -0
- package/dist/database/sqlite-adapter/entries/search/cursor.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/search/date-and-pagination.d.ts +37 -0
- package/dist/database/sqlite-adapter/entries/search/date-and-pagination.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/search/entity-lookups.d.ts +31 -0
- package/dist/database/sqlite-adapter/entries/search/entity-lookups.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/search/fts-and-hybrid.d.ts +44 -0
- package/dist/database/sqlite-adapter/entries/search/fts-and-hybrid.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/search/fts-sanitizer.d.ts +15 -0
- package/dist/database/sqlite-adapter/entries/search/fts-sanitizer.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/search/index.d.ts +8 -0
- package/dist/database/sqlite-adapter/entries/search/index.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/search/query.d.ts +4 -0
- package/dist/database/sqlite-adapter/entries/search/query.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/shared.d.ts +39 -0
- package/dist/database/sqlite-adapter/entries/shared.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/entries/statistics.d.ts +3 -0
- package/dist/database/sqlite-adapter/entries/statistics.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/health-operations.d.ts +10 -0
- package/dist/database/sqlite-adapter/health-operations.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/index.d.ts +2 -0
- package/dist/database/sqlite-adapter/index.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/insights/cross-project.d.ts +42 -0
- package/dist/database/sqlite-adapter/insights/cross-project.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/insights/entry-digest-queries.d.ts +17 -0
- package/dist/database/sqlite-adapter/insights/entry-digest-queries.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/insights/team-collaboration.d.ts +29 -0
- package/dist/database/sqlite-adapter/insights/team-collaboration.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/insights-operations.d.ts +47 -0
- package/dist/database/sqlite-adapter/insights-operations.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/lifecycle-operations.d.ts +32 -0
- package/dist/database/sqlite-adapter/lifecycle-operations.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/members.d.ts +23 -0
- package/dist/database/sqlite-adapter/members.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/native-connection.d.ts +46 -0
- package/dist/database/sqlite-adapter/native-connection.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/relationships.d.ts +26 -0
- package/dist/database/sqlite-adapter/relationships.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/tags.d.ts +16 -0
- package/dist/database/sqlite-adapter/tags.d.ts.map +1 -0
- package/dist/database/sqlite-adapter/vector-operations.d.ts +24 -0
- package/dist/database/sqlite-adapter/vector-operations.d.ts.map +1 -0
- package/dist/errors-MHAM6AKR.js +1 -0
- package/dist/filtering/tool-constants.d.ts +33 -0
- package/dist/filtering/tool-constants.d.ts.map +1 -0
- package/dist/filtering/tool-filter.d.ts +65 -0
- package/dist/filtering/tool-filter.d.ts.map +1 -0
- package/dist/fts-YHUVPPYF.js +2 -0
- package/dist/github/commit-references/enricher.d.ts +12 -0
- package/dist/github/commit-references/enricher.d.ts.map +1 -0
- package/dist/github/commit-references/index.d.ts +4 -0
- package/dist/github/commit-references/index.d.ts.map +1 -0
- package/dist/github/commit-references/parser.d.ts +10 -0
- package/dist/github/commit-references/parser.d.ts.map +1 -0
- package/dist/github/commit-references/resolver.d.ts +14 -0
- package/dist/github/commit-references/resolver.d.ts.map +1 -0
- package/dist/github/github-integration/client.d.ts +29 -0
- package/dist/github/github-integration/client.d.ts.map +1 -0
- package/dist/github/github-integration/index.d.ts +83 -0
- package/dist/github/github-integration/index.d.ts.map +1 -0
- package/dist/github/github-integration/insights.d.ts +11 -0
- package/dist/github/github-integration/insights.d.ts.map +1 -0
- package/dist/github/github-integration/issues.d.ts +25 -0
- package/dist/github/github-integration/issues.d.ts.map +1 -0
- package/dist/github/github-integration/milestones.d.ts +20 -0
- package/dist/github/github-integration/milestones.d.ts.map +1 -0
- package/dist/github/github-integration/projects.d.ts +21 -0
- package/dist/github/github-integration/projects.d.ts.map +1 -0
- package/dist/github/github-integration/pull-requests.d.ts +16 -0
- package/dist/github/github-integration/pull-requests.d.ts.map +1 -0
- package/dist/github/github-integration/repository.d.ts +14 -0
- package/dist/github/github-integration/repository.d.ts.map +1 -0
- package/dist/github/github-integration/types.d.ts +77 -0
- package/dist/github/github-integration/types.d.ts.map +1 -0
- package/dist/handlers/prompts/adversarial-helpers.d.ts +75 -0
- package/dist/handlers/prompts/adversarial-helpers.d.ts.map +1 -0
- package/dist/handlers/prompts/adversarial.d.ts +13 -0
- package/dist/handlers/prompts/adversarial.d.ts.map +1 -0
- package/dist/handlers/prompts/analytics.d.ts +12 -0
- package/dist/handlers/prompts/analytics.d.ts.map +1 -0
- package/dist/handlers/prompts/cms-supervisor.d.ts +8 -0
- package/dist/handlers/prompts/cms-supervisor.d.ts.map +1 -0
- package/dist/handlers/prompts/git.d.ts +8 -0
- package/dist/handlers/prompts/git.d.ts.map +1 -0
- package/dist/handlers/prompts/github.d.ts +12 -0
- package/dist/handlers/prompts/github.d.ts.map +1 -0
- package/dist/handlers/prompts/index.d.ts +53 -0
- package/dist/handlers/prompts/index.d.ts.map +1 -0
- package/dist/handlers/prompts/load-briefing.d.ts +3 -0
- package/dist/handlers/prompts/load-briefing.d.ts.map +1 -0
- package/dist/handlers/prompts/optimizer.d.ts +8 -0
- package/dist/handlers/prompts/optimizer.d.ts.map +1 -0
- package/dist/handlers/prompts/workflow.d.ts +15 -0
- package/dist/handlers/prompts/workflow.d.ts.map +1 -0
- package/dist/handlers/resources/core/agent-context.d.ts +4 -0
- package/dist/handlers/resources/core/agent-context.d.ts.map +1 -0
- package/dist/handlers/resources/core/briefing/context-section.d.ts +57 -0
- package/dist/handlers/resources/core/briefing/context-section.d.ts.map +1 -0
- package/dist/handlers/resources/core/briefing/github-repo-and-kanban.d.ts +57 -0
- package/dist/handlers/resources/core/briefing/github-repo-and-kanban.d.ts.map +1 -0
- package/dist/handlers/resources/core/briefing/github-section.d.ts +88 -0
- package/dist/handlers/resources/core/briefing/github-section.d.ts.map +1 -0
- package/dist/handlers/resources/core/briefing/index.d.ts +11 -0
- package/dist/handlers/resources/core/briefing/index.d.ts.map +1 -0
- package/dist/handlers/resources/core/briefing/insights-section.d.ts +35 -0
- package/dist/handlers/resources/core/briefing/insights-section.d.ts.map +1 -0
- package/dist/handlers/resources/core/briefing/system-section.d.ts +85 -0
- package/dist/handlers/resources/core/briefing/system-section.d.ts.map +1 -0
- package/dist/handlers/resources/core/briefing/user-message.d.ts +46 -0
- package/dist/handlers/resources/core/briefing/user-message.d.ts.map +1 -0
- package/dist/handlers/resources/core/health.d.ts +3 -0
- package/dist/handlers/resources/core/health.d.ts.map +1 -0
- package/dist/handlers/resources/core/index.d.ts +6 -0
- package/dist/handlers/resources/core/index.d.ts.map +1 -0
- package/dist/handlers/resources/core/instructions.d.ts +3 -0
- package/dist/handlers/resources/core/instructions.d.ts.map +1 -0
- package/dist/handlers/resources/core/metrics-resource.d.ts +23 -0
- package/dist/handlers/resources/core/metrics-resource.d.ts.map +1 -0
- package/dist/handlers/resources/core/utilities.d.ts +7 -0
- package/dist/handlers/resources/core/utilities.d.ts.map +1 -0
- package/dist/handlers/resources/github.d.ts +11 -0
- package/dist/handlers/resources/github.d.ts.map +1 -0
- package/dist/handlers/resources/graph.d.ts +12 -0
- package/dist/handlers/resources/graph.d.ts.map +1 -0
- package/dist/handlers/resources/help.d.ts +39 -0
- package/dist/handlers/resources/help.d.ts.map +1 -0
- package/dist/handlers/resources/index.d.ts +37 -0
- package/dist/handlers/resources/index.d.ts.map +1 -0
- package/dist/handlers/resources/insights.d.ts +16 -0
- package/dist/handlers/resources/insights.d.ts.map +1 -0
- package/dist/handlers/resources/shared.d.ts +136 -0
- package/dist/handlers/resources/shared.d.ts.map +1 -0
- package/dist/handlers/resources/staleness.d.ts +3 -0
- package/dist/handlers/resources/staleness.d.ts.map +1 -0
- package/dist/handlers/resources/team.d.ts +6 -0
- package/dist/handlers/resources/team.d.ts.map +1 -0
- package/dist/handlers/resources/templates.d.ts +13 -0
- package/dist/handlers/resources/templates.d.ts.map +1 -0
- package/dist/handlers/resources/tools-catalog.d.ts +3 -0
- package/dist/handlers/resources/tools-catalog.d.ts.map +1 -0
- package/dist/handlers/tools/admin/batch-tools.d.ts +3 -0
- package/dist/handlers/tools/admin/batch-tools.d.ts.map +1 -0
- package/dist/handlers/tools/admin/core-tools.d.ts +3 -0
- package/dist/handlers/tools/admin/core-tools.d.ts.map +1 -0
- package/dist/handlers/tools/admin/index.d.ts +3 -0
- package/dist/handlers/tools/admin/index.d.ts.map +1 -0
- package/dist/handlers/tools/admin/lifecycle-tools.d.ts +3 -0
- package/dist/handlers/tools/admin/lifecycle-tools.d.ts.map +1 -0
- package/dist/handlers/tools/admin/misc-tools.d.ts +3 -0
- package/dist/handlers/tools/admin/misc-tools.d.ts.map +1 -0
- package/dist/handlers/tools/admin/project-tools.d.ts +3 -0
- package/dist/handlers/tools/admin/project-tools.d.ts.map +1 -0
- package/dist/handlers/tools/admin/schemas/crud-batch-schemas.d.ts +609 -0
- package/dist/handlers/tools/admin/schemas/crud-batch-schemas.d.ts.map +1 -0
- package/dist/handlers/tools/admin/schemas/project-and-ops-schemas.d.ts +136 -0
- package/dist/handlers/tools/admin/schemas/project-and-ops-schemas.d.ts.map +1 -0
- package/dist/handlers/tools/admin/schemas.d.ts +3 -0
- package/dist/handlers/tools/admin/schemas.d.ts.map +1 -0
- package/dist/handlers/tools/admin/update_configuration.d.ts +36 -0
- package/dist/handlers/tools/admin/update_configuration.d.ts.map +1 -0
- package/dist/handlers/tools/admin/vector-tools.d.ts +3 -0
- package/dist/handlers/tools/admin/vector-tools.d.ts.map +1 -0
- package/dist/handlers/tools/analytics.d.ts +8 -0
- package/dist/handlers/tools/analytics.d.ts.map +1 -0
- package/dist/handlers/tools/arg-interceptions.d.ts +51 -0
- package/dist/handlers/tools/arg-interceptions.d.ts.map +1 -0
- package/dist/handlers/tools/backup.d.ts +8 -0
- package/dist/handlers/tools/backup.d.ts.map +1 -0
- package/dist/handlers/tools/codemode/code-healer.d.ts +11 -0
- package/dist/handlers/tools/codemode/code-healer.d.ts.map +1 -0
- package/dist/handlers/tools/codemode/handler.d.ts +7 -0
- package/dist/handlers/tools/codemode/handler.d.ts.map +1 -0
- package/dist/handlers/tools/codemode/index.d.ts +2 -0
- package/dist/handlers/tools/codemode/index.d.ts.map +1 -0
- package/dist/handlers/tools/codemode/json-entry-recovery.d.ts +13 -0
- package/dist/handlers/tools/codemode/json-entry-recovery.d.ts.map +1 -0
- package/dist/handlers/tools/codemode/payload-synthesizer.d.ts +17 -0
- package/dist/handlers/tools/codemode/payload-synthesizer.d.ts.map +1 -0
- package/dist/handlers/tools/codemode/schemas.d.ts +77 -0
- package/dist/handlers/tools/codemode/schemas.d.ts.map +1 -0
- package/dist/handlers/tools/codemode/secure-dispatcher.d.ts +25 -0
- package/dist/handlers/tools/codemode/secure-dispatcher.d.ts.map +1 -0
- package/dist/handlers/tools/codemode/singleton-state.d.ts +11 -0
- package/dist/handlers/tools/codemode/singleton-state.d.ts.map +1 -0
- package/dist/handlers/tools/codemode/sql-recovery.d.ts +14 -0
- package/dist/handlers/tools/codemode/sql-recovery.d.ts.map +1 -0
- package/dist/handlers/tools/core/dummy-healing/alias-catalog.d.ts +21 -0
- package/dist/handlers/tools/core/dummy-healing/alias-catalog.d.ts.map +1 -0
- package/dist/handlers/tools/core/dummy-healing/entry-fallbacks.d.ts +4 -0
- package/dist/handlers/tools/core/dummy-healing/entry-fallbacks.d.ts.map +1 -0
- package/dist/handlers/tools/core/dummy-healing/fs-fallbacks.d.ts +19 -0
- package/dist/handlers/tools/core/dummy-healing/fs-fallbacks.d.ts.map +1 -0
- package/dist/handlers/tools/core/dummy-healing/index.d.ts +7 -0
- package/dist/handlers/tools/core/dummy-healing/index.d.ts.map +1 -0
- package/dist/handlers/tools/core/dummy-healing/mcp-fallbacks.d.ts +12 -0
- package/dist/handlers/tools/core/dummy-healing/mcp-fallbacks.d.ts.map +1 -0
- package/dist/handlers/tools/core/dummy-healing.d.ts +2 -0
- package/dist/handlers/tools/core/dummy-healing.d.ts.map +1 -0
- package/dist/handlers/tools/core/index.d.ts +5 -0
- package/dist/handlers/tools/core/index.d.ts.map +1 -0
- package/dist/handlers/tools/core/schemas.d.ts +417 -0
- package/dist/handlers/tools/core/schemas.d.ts.map +1 -0
- package/dist/handlers/tools/core/staleness-tools.d.ts +33 -0
- package/dist/handlers/tools/core/staleness-tools.d.ts.map +1 -0
- package/dist/handlers/tools/core/tools.d.ts +3 -0
- package/dist/handlers/tools/core/tools.d.ts.map +1 -0
- package/dist/handlers/tools/error-fields-mixin.d.ts +10 -0
- package/dist/handlers/tools/error-fields-mixin.d.ts.map +1 -0
- package/dist/handlers/tools/git.d.ts +62 -0
- package/dist/handlers/tools/git.d.ts.map +1 -0
- package/dist/handlers/tools/github/close-issue-tool.d.ts +6 -0
- package/dist/handlers/tools/github/close-issue-tool.d.ts.map +1 -0
- package/dist/handlers/tools/github/copilot-tools.d.ts +8 -0
- package/dist/handlers/tools/github/copilot-tools.d.ts.map +1 -0
- package/dist/handlers/tools/github/create-issue-tool.d.ts +6 -0
- package/dist/handlers/tools/github/create-issue-tool.d.ts.map +1 -0
- package/dist/handlers/tools/github/helpers.d.ts +38 -0
- package/dist/handlers/tools/github/helpers.d.ts.map +1 -0
- package/dist/handlers/tools/github/insights-tools.d.ts +8 -0
- package/dist/handlers/tools/github/insights-tools.d.ts.map +1 -0
- package/dist/handlers/tools/github/issue-tools.d.ts +11 -0
- package/dist/handlers/tools/github/issue-tools.d.ts.map +1 -0
- package/dist/handlers/tools/github/kanban-tools.d.ts +8 -0
- package/dist/handlers/tools/github/kanban-tools.d.ts.map +1 -0
- package/dist/handlers/tools/github/milestone-tools.d.ts +9 -0
- package/dist/handlers/tools/github/milestone-tools.d.ts.map +1 -0
- package/dist/handlers/tools/github/mutation-tools.d.ts +12 -0
- package/dist/handlers/tools/github/mutation-tools.d.ts.map +1 -0
- package/dist/handlers/tools/github/read-tools.d.ts +8 -0
- package/dist/handlers/tools/github/read-tools.d.ts.map +1 -0
- package/dist/handlers/tools/github/schemas.d.ts +823 -0
- package/dist/handlers/tools/github/schemas.d.ts.map +1 -0
- package/dist/handlers/tools/github.d.ts +15 -0
- package/dist/handlers/tools/github.d.ts.map +1 -0
- package/dist/handlers/tools/index.d.ts +29 -0
- package/dist/handlers/tools/index.d.ts.map +1 -0
- package/dist/handlers/tools/io/index.d.ts +2 -0
- package/dist/handlers/tools/io/index.d.ts.map +1 -0
- package/dist/handlers/tools/io/schemas.d.ts +291 -0
- package/dist/handlers/tools/io/schemas.d.ts.map +1 -0
- package/dist/handlers/tools/io/tools.d.ts +3 -0
- package/dist/handlers/tools/io/tools.d.ts.map +1 -0
- package/dist/handlers/tools/relationships.d.ts +8 -0
- package/dist/handlers/tools/relationships.d.ts.map +1 -0
- package/dist/handlers/tools/schemas/constants-and-primitives.d.ts +53 -0
- package/dist/handlers/tools/schemas/constants-and-primitives.d.ts.map +1 -0
- package/dist/handlers/tools/schemas/hallucination-healer.d.ts +8 -0
- package/dist/handlers/tools/schemas/hallucination-healer.d.ts.map +1 -0
- package/dist/handlers/tools/schemas/output-schemas.d.ts +247 -0
- package/dist/handlers/tools/schemas/output-schemas.d.ts.map +1 -0
- package/dist/handlers/tools/schemas.d.ts +7 -0
- package/dist/handlers/tools/schemas.d.ts.map +1 -0
- package/dist/handlers/tools/search/auto.d.ts +38 -0
- package/dist/handlers/tools/search/auto.d.ts.map +1 -0
- package/dist/handlers/tools/search/cross-team.d.ts +132 -0
- package/dist/handlers/tools/search/cross-team.d.ts.map +1 -0
- package/dist/handlers/tools/search/date-range-search.d.ts +3 -0
- package/dist/handlers/tools/search/date-range-search.d.ts.map +1 -0
- package/dist/handlers/tools/search/fts.d.ts +50 -0
- package/dist/handlers/tools/search/fts.d.ts.map +1 -0
- package/dist/handlers/tools/search/helpers.d.ts +52 -0
- package/dist/handlers/tools/search/helpers.d.ts.map +1 -0
- package/dist/handlers/tools/search/hybrid.d.ts +45 -0
- package/dist/handlers/tools/search/hybrid.d.ts.map +1 -0
- package/dist/handlers/tools/search/index.d.ts +3 -0
- package/dist/handlers/tools/search/index.d.ts.map +1 -0
- package/dist/handlers/tools/search/misc-tools.d.ts +3 -0
- package/dist/handlers/tools/search/misc-tools.d.ts.map +1 -0
- package/dist/handlers/tools/search/schemas.d.ts +352 -0
- package/dist/handlers/tools/search/schemas.d.ts.map +1 -0
- package/dist/handlers/tools/search/search-entries.d.ts +3 -0
- package/dist/handlers/tools/search/search-entries.d.ts.map +1 -0
- package/dist/handlers/tools/search/semantic-search.d.ts +3 -0
- package/dist/handlers/tools/search/semantic-search.d.ts.map +1 -0
- package/dist/handlers/tools/team/admin-tools/batch.d.ts +8 -0
- package/dist/handlers/tools/team/admin-tools/batch.d.ts.map +1 -0
- package/dist/handlers/tools/team/admin-tools/crud.d.ts +8 -0
- package/dist/handlers/tools/team/admin-tools/crud.d.ts.map +1 -0
- package/dist/handlers/tools/team/admin-tools/index.d.ts +9 -0
- package/dist/handlers/tools/team/admin-tools/index.d.ts.map +1 -0
- package/dist/handlers/tools/team/alias-tools.d.ts +3 -0
- package/dist/handlers/tools/team/alias-tools.d.ts.map +1 -0
- package/dist/handlers/tools/team/analytics-tools.d.ts +8 -0
- package/dist/handlers/tools/team/analytics-tools.d.ts.map +1 -0
- package/dist/handlers/tools/team/backup-tools.d.ts +8 -0
- package/dist/handlers/tools/team/backup-tools.d.ts.map +1 -0
- package/dist/handlers/tools/team/core-tools.d.ts +8 -0
- package/dist/handlers/tools/team/core-tools.d.ts.map +1 -0
- package/dist/handlers/tools/team/export-tools.d.ts +8 -0
- package/dist/handlers/tools/team/export-tools.d.ts.map +1 -0
- package/dist/handlers/tools/team/helpers.d.ts +30 -0
- package/dist/handlers/tools/team/helpers.d.ts.map +1 -0
- package/dist/handlers/tools/team/index.d.ts +31 -0
- package/dist/handlers/tools/team/index.d.ts.map +1 -0
- package/dist/handlers/tools/team/io-tools.d.ts +11 -0
- package/dist/handlers/tools/team/io-tools.d.ts.map +1 -0
- package/dist/handlers/tools/team/member-tools.d.ts +8 -0
- package/dist/handlers/tools/team/member-tools.d.ts.map +1 -0
- package/dist/handlers/tools/team/rbac.d.ts +28 -0
- package/dist/handlers/tools/team/rbac.d.ts.map +1 -0
- package/dist/handlers/tools/team/relationship-tools.d.ts +8 -0
- package/dist/handlers/tools/team/relationship-tools.d.ts.map +1 -0
- package/dist/handlers/tools/team/schemas/admin-batch-schemas.d.ts +618 -0
- package/dist/handlers/tools/team/schemas/admin-batch-schemas.d.ts.map +1 -0
- package/dist/handlers/tools/team/schemas/analytics-vector-schemas.d.ts +464 -0
- package/dist/handlers/tools/team/schemas/analytics-vector-schemas.d.ts.map +1 -0
- package/dist/handlers/tools/team/schemas/core-search-schemas.d.ts +525 -0
- package/dist/handlers/tools/team/schemas/core-search-schemas.d.ts.map +1 -0
- package/dist/handlers/tools/team/schemas/io-backup-schemas.d.ts +419 -0
- package/dist/handlers/tools/team/schemas/io-backup-schemas.d.ts.map +1 -0
- package/dist/handlers/tools/team/schemas.d.ts +8 -0
- package/dist/handlers/tools/team/schemas.d.ts.map +1 -0
- package/dist/handlers/tools/team/search-tools.d.ts +8 -0
- package/dist/handlers/tools/team/search-tools.d.ts.map +1 -0
- package/dist/handlers/tools/team/vector-tools.d.ts +9 -0
- package/dist/handlers/tools/team/vector-tools.d.ts.map +1 -0
- package/dist/index.d.ts +10 -823
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -13
- package/dist/markdown/converters/index.d.ts +26 -0
- package/dist/markdown/converters/index.d.ts.map +1 -0
- package/dist/markdown/converters/logseq.d.ts +14 -0
- package/dist/markdown/converters/logseq.d.ts.map +1 -0
- package/dist/markdown/converters/notion.d.ts +14 -0
- package/dist/markdown/converters/notion.d.ts.map +1 -0
- package/dist/markdown/converters/obsidian.d.ts +14 -0
- package/dist/markdown/converters/obsidian.d.ts.map +1 -0
- package/dist/markdown/converters/utils.d.ts +4 -0
- package/dist/markdown/converters/utils.d.ts.map +1 -0
- package/dist/markdown/converters/yaml-parser.d.ts +32 -0
- package/dist/markdown/converters/yaml-parser.d.ts.map +1 -0
- package/dist/markdown/exporter.d.ts +54 -0
- package/dist/markdown/exporter.d.ts.map +1 -0
- package/dist/markdown/frontmatter.d.ts +47 -0
- package/dist/markdown/frontmatter.d.ts.map +1 -0
- package/dist/markdown/importer.d.ts +81 -0
- package/dist/markdown/importer.d.ts.map +1 -0
- package/dist/markdown/index.d.ts +14 -0
- package/dist/markdown/index.d.ts.map +1 -0
- package/dist/observability/index.d.ts +19 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/interceptor.d.ts +27 -0
- package/dist/observability/interceptor.d.ts.map +1 -0
- package/dist/observability/latency-tracker.d.ts +47 -0
- package/dist/observability/latency-tracker.d.ts.map +1 -0
- package/dist/observability/metrics-server.d.ts +3 -0
- package/dist/observability/metrics-server.d.ts.map +1 -0
- package/dist/observability/metrics.d.ts +138 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/prometheus-formatter.d.ts +14 -0
- package/dist/observability/prometheus-formatter.d.ts.map +1 -0
- package/dist/observability/token-estimator.d.ts +44 -0
- package/dist/observability/token-estimator.d.ts.map +1 -0
- package/dist/security-utils-P4P6A2DG.js +2 -0
- package/dist/server/auto-prune.d.ts +48 -0
- package/dist/server/auto-prune.d.ts.map +1 -0
- package/dist/server/digest-reporter.d.ts +16 -0
- package/dist/server/digest-reporter.d.ts.map +1 -0
- package/dist/server/mcp-server/core.d.ts +3 -0
- package/dist/server/mcp-server/core.d.ts.map +1 -0
- package/dist/server/mcp-server/index.d.ts +4 -0
- package/dist/server/mcp-server/index.d.ts.map +1 -0
- package/dist/server/mcp-server/initialization.d.ts +13 -0
- package/dist/server/mcp-server/initialization.d.ts.map +1 -0
- package/dist/server/mcp-server/tool-registration/call-interceptor.d.ts +6 -0
- package/dist/server/mcp-server/tool-registration/call-interceptor.d.ts.map +1 -0
- package/dist/server/mcp-server/tool-registration/index.d.ts +4 -0
- package/dist/server/mcp-server/tool-registration/index.d.ts.map +1 -0
- package/dist/server/mcp-server/tool-registration/list-interceptor.d.ts +4 -0
- package/dist/server/mcp-server/tool-registration/list-interceptor.d.ts.map +1 -0
- package/dist/server/mcp-server/tool-registration/register-tools.d.ts +18 -0
- package/dist/server/mcp-server/tool-registration/register-tools.d.ts.map +1 -0
- package/dist/server/mcp-server/tool-registration.d.ts +2 -0
- package/dist/server/mcp-server/tool-registration.d.ts.map +1 -0
- package/dist/server/mcp-server/types.d.ts +78 -0
- package/dist/server/mcp-server/types.d.ts.map +1 -0
- package/dist/server/registration.d.ts +73 -0
- package/dist/server/registration.d.ts.map +1 -0
- package/dist/server/scheduler.d.ts +129 -0
- package/dist/server/scheduler.d.ts.map +1 -0
- package/dist/server/subscription-manager.d.ts +46 -0
- package/dist/server/subscription-manager.d.ts.map +1 -0
- package/dist/tools-BOQV7QD3.js +6 -0
- package/dist/transports/http/handlers.d.ts +25 -0
- package/dist/transports/http/handlers.d.ts.map +1 -0
- package/dist/transports/http/index.d.ts +8 -0
- package/dist/transports/http/index.d.ts.map +1 -0
- package/dist/transports/http/security.d.ts +43 -0
- package/dist/transports/http/security.d.ts.map +1 -0
- package/dist/transports/http/server/http-transport.d.ts +25 -0
- package/dist/transports/http/server/http-transport.d.ts.map +1 -0
- package/dist/transports/http/server/index.d.ts +4 -0
- package/dist/transports/http/server/index.d.ts.map +1 -0
- package/dist/transports/http/server/legacy-sse.d.ts +30 -0
- package/dist/transports/http/server/legacy-sse.d.ts.map +1 -0
- package/dist/transports/http/server/protocol-handlers.d.ts +9 -0
- package/dist/transports/http/server/protocol-handlers.d.ts.map +1 -0
- package/dist/transports/http/types.d.ts +95 -0
- package/dist/transports/http/types.d.ts.map +1 -0
- package/dist/types/auto-context.d.ts +44 -0
- package/dist/types/auto-context.d.ts.map +1 -0
- package/dist/types/entities.d.ts +180 -0
- package/dist/types/entities.d.ts.map +1 -0
- package/dist/types/error-types.d.ts +48 -0
- package/dist/types/error-types.d.ts.map +1 -0
- package/dist/types/errors.d.ts +108 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/filtering.d.ts +34 -0
- package/dist/types/filtering.d.ts.map +1 -0
- package/dist/types/github.d.ts +202 -0
- package/dist/types/github.d.ts.map +1 -0
- package/dist/types/index.d.ts +326 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/config-manager.d.ts +24 -0
- package/dist/utils/config-manager.d.ts.map +1 -0
- package/dist/utils/config-resolver.d.ts +41 -0
- package/dist/utils/config-resolver.d.ts.map +1 -0
- package/dist/utils/error-helpers.d.ts +38 -0
- package/dist/utils/error-helpers.d.ts.map +1 -0
- package/dist/utils/errors/error-response-fields.d.ts +28 -0
- package/dist/utils/errors/error-response-fields.d.ts.map +1 -0
- package/dist/utils/errors/suggestions.d.ts +29 -0
- package/dist/utils/errors/suggestions.d.ts.map +1 -0
- package/dist/utils/github-helpers.d.ts +12 -0
- package/dist/utils/github-helpers.d.ts.map +1 -0
- package/dist/utils/issue-logger.d.ts +10 -0
- package/dist/utils/issue-logger.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +30 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/maintenance-lock.d.ts +34 -0
- package/dist/utils/maintenance-lock.d.ts.map +1 -0
- package/dist/utils/mcp-logger.d.ts +73 -0
- package/dist/utils/mcp-logger.d.ts.map +1 -0
- package/dist/utils/progress-utils.d.ts +53 -0
- package/dist/utils/progress-utils.d.ts.map +1 -0
- package/dist/utils/query-helpers.d.ts +43 -0
- package/dist/utils/query-helpers.d.ts.map +1 -0
- package/dist/utils/request-context.d.ts +9 -0
- package/dist/utils/request-context.d.ts.map +1 -0
- package/dist/utils/resource-annotations.d.ts +36 -0
- package/dist/utils/resource-annotations.d.ts.map +1 -0
- package/dist/utils/security-utils.d.ts +113 -0
- package/dist/utils/security-utils.d.ts.map +1 -0
- package/dist/utils/vector-index-helpers.d.ts +14 -0
- package/dist/utils/vector-index-helpers.d.ts.map +1 -0
- package/dist/utils/workspace-resolver.d.ts +40 -0
- package/dist/utils/workspace-resolver.d.ts.map +1 -0
- package/dist/vector/vector-search-manager/VectorSearchManagerProxy.d.ts +5 -0
- package/dist/vector/vector-search-manager/VectorSearchManagerProxy.d.ts.map +1 -0
- package/dist/vector/vector-search-manager/index.d.ts +3 -0
- package/dist/vector/vector-search-manager/index.d.ts.map +1 -0
- package/dist/vector/vector-search-manager/manager.d.ts +75 -0
- package/dist/vector/vector-search-manager/manager.d.ts.map +1 -0
- package/dist/vector/vector-search-manager/rebuild.d.ts +20 -0
- package/dist/vector/vector-search-manager/rebuild.d.ts.map +1 -0
- package/dist/vector/vector-search-manager/types.d.ts +12 -0
- package/dist/vector/vector-search-manager/types.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/agent-exec.d.ts +2 -0
- package/dist/vendor/lib-agent-exec/agent-exec.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/command-builder.d.ts +11 -0
- package/dist/vendor/lib-agent-exec/command-builder.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/command-utils.d.ts +29 -0
- package/dist/vendor/lib-agent-exec/command-utils.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/environment.d.ts +4 -0
- package/dist/vendor/lib-agent-exec/environment.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/eval-healer.d.ts +15 -0
- package/dist/vendor/lib-agent-exec/eval-healer.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/execution-engine.d.ts +4 -0
- package/dist/vendor/lib-agent-exec/execution-engine.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/help.d.ts +3 -0
- package/dist/vendor/lib-agent-exec/help.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/cloud-cli-interceptor.d.ts +3 -0
- package/dist/vendor/lib-agent-exec/interceptors/cloud-cli-interceptor.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/docker-interceptor.d.ts +3 -0
- package/dist/vendor/lib-agent-exec/interceptors/docker-interceptor.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/git-interceptor.d.ts +3 -0
- package/dist/vendor/lib-agent-exec/interceptors/git-interceptor.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/index.d.ts +9 -0
- package/dist/vendor/lib-agent-exec/interceptors/index.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/mutating-interceptors.d.ts +7 -0
- package/dist/vendor/lib-agent-exec/interceptors/mutating-interceptors.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/package-manager-interceptor.d.ts +3 -0
- package/dist/vendor/lib-agent-exec/interceptors/package-manager-interceptor.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/repl-tui-interceptor.d.ts +3 -0
- package/dist/vendor/lib-agent-exec/interceptors/repl-tui-interceptor.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/search-interceptor.d.ts +15 -0
- package/dist/vendor/lib-agent-exec/interceptors/search-interceptor.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/structural-interceptors.d.ts +15 -0
- package/dist/vendor/lib-agent-exec/interceptors/structural-interceptors.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/system-interceptor.d.ts +3 -0
- package/dist/vendor/lib-agent-exec/interceptors/system-interceptor.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/types.d.ts +11 -0
- package/dist/vendor/lib-agent-exec/interceptors/types.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/interceptors/utils.d.ts +5 -0
- package/dist/vendor/lib-agent-exec/interceptors/utils.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/io-controller.d.ts +48 -0
- package/dist/vendor/lib-agent-exec/io-controller.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/io-utils.d.ts +12 -0
- package/dist/vendor/lib-agent-exec/io-utils.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/path-healer.d.ts +15 -0
- package/dist/vendor/lib-agent-exec/path-healer.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/process-controller.d.ts +38 -0
- package/dist/vendor/lib-agent-exec/process-controller.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/process-manager.d.ts +6 -0
- package/dist/vendor/lib-agent-exec/process-manager.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/prompt-detector.d.ts +2 -0
- package/dist/vendor/lib-agent-exec/prompt-detector.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/schema.d.ts +182 -0
- package/dist/vendor/lib-agent-exec/schema.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/stream-manager.d.ts +20 -0
- package/dist/vendor/lib-agent-exec/stream-manager.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/utils.d.ts +17 -0
- package/dist/vendor/lib-agent-exec/utils.d.ts.map +1 -0
- package/dist/vendor/lib-agent-exec/webhook-template.d.ts +2 -0
- package/dist/vendor/lib-agent-exec/webhook-template.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/cache.d.ts +56 -0
- package/dist/vendor/lib-git-history/cache.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/cli.d.ts +147 -0
- package/dist/vendor/lib-git-history/cli.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/constants.d.ts +36 -0
- package/dist/vendor/lib-git-history/constants.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/git-numstat.d.ts +7 -0
- package/dist/vendor/lib-git-history/git-numstat.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/git-patch.d.ts +3 -0
- package/dist/vendor/lib-git-history/git-patch.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/git-runner.d.ts +25 -0
- package/dist/vendor/lib-git-history/git-runner.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/parser-batch.d.ts +5 -0
- package/dist/vendor/lib-git-history/parser-batch.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/parser-metadata.d.ts +3 -0
- package/dist/vendor/lib-git-history/parser-metadata.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/parser-record.d.ts +37 -0
- package/dist/vendor/lib-git-history/parser-record.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/parser-utils.d.ts +22 -0
- package/dist/vendor/lib-git-history/parser-utils.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/parser.d.ts +4 -0
- package/dist/vendor/lib-git-history/parser.d.ts.map +1 -0
- package/dist/vendor/lib-git-history/schema.d.ts +131 -0
- package/dist/vendor/lib-git-history/schema.d.ts.map +1 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/worker-script.js +2937 -342
- package/package.json +130 -106
- package/skills/memory-journal-mcp/SKILL.md +41 -0
- package/dist/chunk-6OHRCNYW.js +0 -3231
- package/dist/chunk-JFMITANR.js +0 -5168
- package/dist/chunk-UHSO65A4.js +0 -8937
- package/dist/chunk-V3UTFQQK.js +0 -5538
- package/dist/cli.d.ts +0 -2
- package/dist/resources-IJVKDFGS.js +0 -2
- package/dist/tools-44DGXE3V.js +0 -2
- package/dist/worker-script.d.ts +0 -2
- package/skills/README.md +0 -121
- package/skills/adversarial-performance/SKILL.md +0 -139
- package/skills/adversarial-performance/references/audit-categories.md +0 -462
- package/skills/adversarial-performance/references/copilot-performance-prompts.md +0 -44
- package/skills/adversarial-performance/references/copilot-usage.md +0 -16
- package/skills/adversarial-performance/references/feedback-loop.md +0 -177
- package/skills/adversarial-performance/references/multi-pass-performance-protocol.md +0 -398
- package/skills/adversarial-planner/SKILL.md +0 -89
- package/skills/adversarial-planner/references/copilot-integration.md +0 -83
- package/skills/adversarial-planner/references/copilot-usage.md +0 -16
- package/skills/adversarial-planner/references/feedback-loop.md +0 -148
- package/skills/adversarial-planner/references/multi-pass-protocol.md +0 -229
- package/skills/adversarial-security/SKILL.md +0 -149
- package/skills/adversarial-security/references/adversarial-base-protocol.md +0 -44
- package/skills/adversarial-security/references/audit-categories.md +0 -723
- package/skills/adversarial-security/references/copilot-security-prompts.md +0 -142
- package/skills/adversarial-security/references/copilot-usage.md +0 -16
- package/skills/adversarial-security/references/feedback-loop.md +0 -206
- package/skills/adversarial-security/references/journal-opt-out.md +0 -7
- package/skills/adversarial-security/references/multi-pass-security-protocol.md +0 -403
- package/skills/adversarial-skill-audit/SKILL.md +0 -118
- package/skills/adversarial-skill-audit/references/audit-categories.md +0 -308
- package/skills/adversarial-skill-audit/references/copilot-skill-prompts.md +0 -68
- package/skills/adversarial-skill-audit/references/copilot-usage.md +0 -16
- package/skills/adversarial-skill-audit/references/feedback-loop.md +0 -155
- package/skills/adversarial-skill-audit/references/multi-pass-skill-protocol.md +0 -367
- package/skills/adversarial-skill-audit/scripts/check-skills.ps1 +0 -48
- package/skills/adversarial-skill-audit/scripts/run-copilot.ps1 +0 -52
- package/skills/adversarial-workflow-audit/SKILL.md +0 -82
- package/skills/adversarial-workflow-audit/references/audit-categories.md +0 -28
- package/skills/adversarial-workflow-audit/references/copilot-usage.md +0 -16
- package/skills/adversarial-workflow-audit/scripts/check-workflows.ps1 +0 -24
- package/skills/agents-sdk/SKILL.md +0 -220
- package/skills/agents-sdk/references/callable.md +0 -92
- package/skills/agents-sdk/references/codemode.md +0 -209
- package/skills/agents-sdk/references/email.md +0 -144
- package/skills/agents-sdk/references/mcp/SKILL.md +0 -65
- package/skills/agents-sdk/references/mcp/code-mode-reference.md +0 -245
- package/skills/agents-sdk/references/mcp/oauth-reference.md +0 -359
- package/skills/agents-sdk/references/mcp/references/architecture-reference.md +0 -208
- package/skills/agents-sdk/references/mcp/references/cloudflare-quickstart.md +0 -156
- package/skills/agents-sdk/references/mcp/references/error-handling.md +0 -343
- package/skills/agents-sdk/references/mcp/references/http-security.md +0 -164
- package/skills/agents-sdk/references/mcp/references/implementation-guide.md +0 -507
- package/skills/agents-sdk/references/mcp/references/testing-reference.md +0 -171
- package/skills/agents-sdk/references/mcp.md +0 -157
- package/skills/agents-sdk/references/state-scheduling.md +0 -164
- package/skills/agents-sdk/references/streaming-chat.md +0 -168
- package/skills/agents-sdk/references/workflows.md +0 -136
- package/skills/auth-identity/SKILL.md +0 -48
- package/skills/autonomous-dev/SKILL.md +0 -79
- package/skills/autonomous-dev/references/workflow_orchestration.md +0 -22
- package/skills/aws/SKILL.md +0 -39
- package/skills/azure/SKILL.md +0 -38
- package/skills/bin/sync.js +0 -56
- package/skills/biome/SKILL.md +0 -59
- package/skills/bun/SKILL.md +0 -162
- package/skills/cloudflare/SKILL.md +0 -37
- package/skills/cloudflare/references/agents-sdk/README.md +0 -95
- package/skills/cloudflare/references/agents-sdk/api.md +0 -195
- package/skills/cloudflare/references/agents-sdk/configuration.md +0 -178
- package/skills/cloudflare/references/agents-sdk/gotchas.md +0 -173
- package/skills/cloudflare/references/agents-sdk/patterns.md +0 -215
- package/skills/cloudflare/references/ai-gateway/README.md +0 -176
- package/skills/cloudflare/references/ai-gateway/configuration.md +0 -117
- package/skills/cloudflare/references/ai-gateway/dynamic-routing.md +0 -88
- package/skills/cloudflare/references/ai-gateway/features.md +0 -96
- package/skills/cloudflare/references/ai-gateway/sdk-integration.md +0 -110
- package/skills/cloudflare/references/ai-gateway/troubleshooting.md +0 -90
- package/skills/cloudflare/references/ai-search/README.md +0 -145
- package/skills/cloudflare/references/ai-search/api.md +0 -87
- package/skills/cloudflare/references/ai-search/configuration.md +0 -91
- package/skills/cloudflare/references/ai-search/gotchas.md +0 -92
- package/skills/cloudflare/references/ai-search/patterns.md +0 -87
- package/skills/cloudflare/references/analytics-engine/README.md +0 -96
- package/skills/cloudflare/references/analytics-engine/api.md +0 -112
- package/skills/cloudflare/references/analytics-engine/configuration.md +0 -107
- package/skills/cloudflare/references/analytics-engine/gotchas.md +0 -87
- package/skills/cloudflare/references/analytics-engine/patterns.md +0 -83
- package/skills/cloudflare/references/api/README.md +0 -66
- package/skills/cloudflare/references/api/api.md +0 -205
- package/skills/cloudflare/references/api/configuration.md +0 -158
- package/skills/cloudflare/references/api/gotchas.md +0 -231
- package/skills/cloudflare/references/api/patterns.md +0 -208
- package/skills/cloudflare/references/api-shield/README.md +0 -44
- package/skills/cloudflare/references/api-shield/api.md +0 -153
- package/skills/cloudflare/references/api-shield/configuration.md +0 -210
- package/skills/cloudflare/references/api-shield/gotchas.md +0 -132
- package/skills/cloudflare/references/api-shield/patterns.md +0 -185
- package/skills/cloudflare/references/argo-smart-routing/README.md +0 -96
- package/skills/cloudflare/references/argo-smart-routing/api.md +0 -253
- package/skills/cloudflare/references/argo-smart-routing/configuration.md +0 -205
- package/skills/cloudflare/references/argo-smart-routing/gotchas.md +0 -115
- package/skills/cloudflare/references/argo-smart-routing/patterns.md +0 -107
- package/skills/cloudflare/references/bindings/README.md +0 -127
- package/skills/cloudflare/references/bindings/api.md +0 -214
- package/skills/cloudflare/references/bindings/configuration.md +0 -200
- package/skills/cloudflare/references/bindings/gotchas.md +0 -210
- package/skills/cloudflare/references/bindings/patterns.md +0 -205
- package/skills/cloudflare/references/bot-management/README.md +0 -95
- package/skills/cloudflare/references/bot-management/api.md +0 -175
- package/skills/cloudflare/references/bot-management/configuration.md +0 -175
- package/skills/cloudflare/references/bot-management/gotchas.md +0 -116
- package/skills/cloudflare/references/bot-management/patterns.md +0 -181
- package/skills/cloudflare/references/browser-rendering/README.md +0 -84
- package/skills/cloudflare/references/browser-rendering/api.md +0 -108
- package/skills/cloudflare/references/browser-rendering/configuration.md +0 -78
- package/skills/cloudflare/references/browser-rendering/gotchas.md +0 -91
- package/skills/cloudflare/references/browser-rendering/patterns.md +0 -93
- package/skills/cloudflare/references/c3/README.md +0 -111
- package/skills/cloudflare/references/c3/api.md +0 -71
- package/skills/cloudflare/references/c3/configuration.md +0 -85
- package/skills/cloudflare/references/c3/gotchas.md +0 -97
- package/skills/cloudflare/references/c3/patterns.md +0 -84
- package/skills/cloudflare/references/cache-reserve/README.md +0 -150
- package/skills/cloudflare/references/cache-reserve/api.md +0 -184
- package/skills/cloudflare/references/cache-reserve/configuration.md +0 -170
- package/skills/cloudflare/references/cache-reserve/gotchas.md +0 -136
- package/skills/cloudflare/references/cache-reserve/patterns.md +0 -197
- package/skills/cloudflare/references/containers/README.md +0 -87
- package/skills/cloudflare/references/containers/api.md +0 -197
- package/skills/cloudflare/references/containers/configuration.md +0 -191
- package/skills/cloudflare/references/containers/gotchas.md +0 -182
- package/skills/cloudflare/references/containers/patterns.md +0 -204
- package/skills/cloudflare/references/cron-triggers/README.md +0 -101
- package/skills/cloudflare/references/cron-triggers/api.md +0 -224
- package/skills/cloudflare/references/cron-triggers/configuration.md +0 -190
- package/skills/cloudflare/references/cron-triggers/gotchas.md +0 -207
- package/skills/cloudflare/references/cron-triggers/patterns.md +0 -274
- package/skills/cloudflare/references/d1/README.md +0 -137
- package/skills/cloudflare/references/d1/api.md +0 -213
- package/skills/cloudflare/references/d1/configuration.md +0 -198
- package/skills/cloudflare/references/d1/gotchas.md +0 -98
- package/skills/cloudflare/references/d1/patterns.md +0 -240
- package/skills/cloudflare/references/ddos/README.md +0 -42
- package/skills/cloudflare/references/ddos/api.md +0 -158
- package/skills/cloudflare/references/ddos/configuration.md +0 -94
- package/skills/cloudflare/references/ddos/gotchas.md +0 -114
- package/skills/cloudflare/references/ddos/patterns.md +0 -220
- package/skills/cloudflare/references/decision-trees.md +0 -95
- package/skills/cloudflare/references/do-storage/README.md +0 -79
- package/skills/cloudflare/references/do-storage/api.md +0 -107
- package/skills/cloudflare/references/do-storage/configuration.md +0 -114
- package/skills/cloudflare/references/do-storage/gotchas.md +0 -153
- package/skills/cloudflare/references/do-storage/patterns.md +0 -210
- package/skills/cloudflare/references/do-storage/testing.md +0 -186
- package/skills/cloudflare/references/durable-objects/README.md +0 -194
- package/skills/cloudflare/references/durable-objects/api.md +0 -205
- package/skills/cloudflare/references/durable-objects/configuration.md +0 -160
- package/skills/cloudflare/references/durable-objects/gotchas.md +0 -200
- package/skills/cloudflare/references/durable-objects/patterns.md +0 -205
- package/skills/cloudflare/references/email-routing/README.md +0 -89
- package/skills/cloudflare/references/email-routing/api.md +0 -192
- package/skills/cloudflare/references/email-routing/configuration.md +0 -187
- package/skills/cloudflare/references/email-routing/gotchas.md +0 -203
- package/skills/cloudflare/references/email-routing/patterns.md +0 -241
- package/skills/cloudflare/references/email-workers/README.md +0 -153
- package/skills/cloudflare/references/email-workers/api.md +0 -227
- package/skills/cloudflare/references/email-workers/configuration.md +0 -115
- package/skills/cloudflare/references/email-workers/gotchas.md +0 -133
- package/skills/cloudflare/references/email-workers/patterns.md +0 -108
- package/skills/cloudflare/references/graphql-api/README.md +0 -147
- package/skills/cloudflare/references/graphql-api/api.md +0 -175
- package/skills/cloudflare/references/graphql-api/configuration.md +0 -151
- package/skills/cloudflare/references/graphql-api/gotchas.md +0 -111
- package/skills/cloudflare/references/graphql-api/patterns.md +0 -276
- package/skills/cloudflare/references/hyperdrive/README.md +0 -84
- package/skills/cloudflare/references/hyperdrive/api.md +0 -149
- package/skills/cloudflare/references/hyperdrive/configuration.md +0 -166
- package/skills/cloudflare/references/hyperdrive/gotchas.md +0 -77
- package/skills/cloudflare/references/hyperdrive/patterns.md +0 -203
- package/skills/cloudflare/references/images/README.md +0 -65
- package/skills/cloudflare/references/images/api.md +0 -101
- package/skills/cloudflare/references/images/configuration.md +0 -206
- package/skills/cloudflare/references/images/gotchas.md +0 -106
- package/skills/cloudflare/references/images/patterns.md +0 -126
- package/skills/cloudflare/references/kv/README.md +0 -90
- package/skills/cloudflare/references/kv/api.md +0 -163
- package/skills/cloudflare/references/kv/configuration.md +0 -148
- package/skills/cloudflare/references/kv/gotchas.md +0 -133
- package/skills/cloudflare/references/kv/patterns.md +0 -195
- package/skills/cloudflare/references/miniflare/README.md +0 -113
- package/skills/cloudflare/references/miniflare/api.md +0 -204
- package/skills/cloudflare/references/miniflare/configuration.md +0 -174
- package/skills/cloudflare/references/miniflare/gotchas.md +0 -179
- package/skills/cloudflare/references/miniflare/patterns.md +0 -187
- package/skills/cloudflare/references/network-interconnect/README.md +0 -104
- package/skills/cloudflare/references/network-interconnect/api.md +0 -220
- package/skills/cloudflare/references/network-interconnect/configuration.md +0 -123
- package/skills/cloudflare/references/network-interconnect/gotchas.md +0 -175
- package/skills/cloudflare/references/network-interconnect/patterns.md +0 -174
- package/skills/cloudflare/references/observability/README.md +0 -93
- package/skills/cloudflare/references/observability/api.md +0 -168
- package/skills/cloudflare/references/observability/configuration.md +0 -178
- package/skills/cloudflare/references/observability/gotchas.md +0 -125
- package/skills/cloudflare/references/observability/patterns.md +0 -105
- package/skills/cloudflare/references/pages/README.md +0 -92
- package/skills/cloudflare/references/pages/api.md +0 -205
- package/skills/cloudflare/references/pages/configuration.md +0 -216
- package/skills/cloudflare/references/pages/gotchas.md +0 -218
- package/skills/cloudflare/references/pages/patterns.md +0 -215
- package/skills/cloudflare/references/pages-functions/README.md +0 -104
- package/skills/cloudflare/references/pages-functions/api.md +0 -159
- package/skills/cloudflare/references/pages-functions/configuration.md +0 -130
- package/skills/cloudflare/references/pages-functions/gotchas.md +0 -102
- package/skills/cloudflare/references/pages-functions/patterns.md +0 -148
- package/skills/cloudflare/references/pipelines/README.md +0 -109
- package/skills/cloudflare/references/pipelines/api.md +0 -214
- package/skills/cloudflare/references/pipelines/configuration.md +0 -98
- package/skills/cloudflare/references/pipelines/gotchas.md +0 -84
- package/skills/cloudflare/references/pipelines/patterns.md +0 -87
- package/skills/cloudflare/references/product-index.md +0 -112
- package/skills/cloudflare/references/pulumi/README.md +0 -113
- package/skills/cloudflare/references/pulumi/api.md +0 -230
- package/skills/cloudflare/references/pulumi/configuration.md +0 -213
- package/skills/cloudflare/references/pulumi/gotchas.md +0 -205
- package/skills/cloudflare/references/pulumi/patterns.md +0 -260
- package/skills/cloudflare/references/queues/README.md +0 -99
- package/skills/cloudflare/references/queues/api.md +0 -211
- package/skills/cloudflare/references/queues/configuration.md +0 -151
- package/skills/cloudflare/references/queues/gotchas.md +0 -210
- package/skills/cloudflare/references/queues/patterns.md +0 -220
- package/skills/cloudflare/references/r2/README.md +0 -97
- package/skills/cloudflare/references/r2/api.md +0 -235
- package/skills/cloudflare/references/r2/configuration.md +0 -176
- package/skills/cloudflare/references/r2/gotchas.md +0 -190
- package/skills/cloudflare/references/r2/patterns.md +0 -203
- package/skills/cloudflare/references/r2-data-catalog/README.md +0 -157
- package/skills/cloudflare/references/r2-data-catalog/api.md +0 -199
- package/skills/cloudflare/references/r2-data-catalog/configuration.md +0 -205
- package/skills/cloudflare/references/r2-data-catalog/gotchas.md +0 -170
- package/skills/cloudflare/references/r2-data-catalog/patterns.md +0 -191
- package/skills/cloudflare/references/r2-sql/README.md +0 -138
- package/skills/cloudflare/references/r2-sql/SKILL.md.backup +0 -512
- package/skills/cloudflare/references/r2-sql/api.md +0 -159
- package/skills/cloudflare/references/r2-sql/configuration.md +0 -152
- package/skills/cloudflare/references/r2-sql/gotchas.md +0 -228
- package/skills/cloudflare/references/r2-sql/patterns.md +0 -230
- package/skills/cloudflare/references/realtime-sfu/README.md +0 -66
- package/skills/cloudflare/references/realtime-sfu/api.md +0 -164
- package/skills/cloudflare/references/realtime-sfu/configuration.md +0 -141
- package/skills/cloudflare/references/realtime-sfu/gotchas.md +0 -138
- package/skills/cloudflare/references/realtime-sfu/patterns.md +0 -187
- package/skills/cloudflare/references/realtimekit/README.md +0 -118
- package/skills/cloudflare/references/realtimekit/api.md +0 -234
- package/skills/cloudflare/references/realtimekit/configuration.md +0 -226
- package/skills/cloudflare/references/realtimekit/gotchas.md +0 -206
- package/skills/cloudflare/references/realtimekit/patterns.md +0 -240
- package/skills/cloudflare/references/sandbox/README.md +0 -104
- package/skills/cloudflare/references/sandbox/api.md +0 -200
- package/skills/cloudflare/references/sandbox/configuration.md +0 -154
- package/skills/cloudflare/references/sandbox/gotchas.md +0 -201
- package/skills/cloudflare/references/sandbox/patterns.md +0 -195
- package/skills/cloudflare/references/secrets-store/README.md +0 -77
- package/skills/cloudflare/references/secrets-store/api.md +0 -199
- package/skills/cloudflare/references/secrets-store/configuration.md +0 -187
- package/skills/cloudflare/references/secrets-store/gotchas.md +0 -97
- package/skills/cloudflare/references/secrets-store/patterns.md +0 -218
- package/skills/cloudflare/references/smart-placement/README.md +0 -143
- package/skills/cloudflare/references/smart-placement/api.md +0 -192
- package/skills/cloudflare/references/smart-placement/configuration.md +0 -202
- package/skills/cloudflare/references/smart-placement/gotchas.md +0 -180
- package/skills/cloudflare/references/smart-placement/patterns.md +0 -190
- package/skills/cloudflare/references/snippets/README.md +0 -74
- package/skills/cloudflare/references/snippets/api.md +0 -214
- package/skills/cloudflare/references/snippets/configuration.md +0 -239
- package/skills/cloudflare/references/snippets/gotchas.md +0 -104
- package/skills/cloudflare/references/snippets/patterns.md +0 -135
- package/skills/cloudflare/references/spectrum/README.md +0 -52
- package/skills/cloudflare/references/spectrum/api.md +0 -184
- package/skills/cloudflare/references/spectrum/configuration.md +0 -203
- package/skills/cloudflare/references/spectrum/gotchas.md +0 -155
- package/skills/cloudflare/references/spectrum/patterns.md +0 -206
- package/skills/cloudflare/references/static-assets/README.md +0 -65
- package/skills/cloudflare/references/static-assets/api.md +0 -201
- package/skills/cloudflare/references/static-assets/configuration.md +0 -186
- package/skills/cloudflare/references/static-assets/gotchas.md +0 -164
- package/skills/cloudflare/references/static-assets/patterns.md +0 -189
- package/skills/cloudflare/references/stream/README.md +0 -123
- package/skills/cloudflare/references/stream/api-live.md +0 -202
- package/skills/cloudflare/references/stream/api.md +0 -206
- package/skills/cloudflare/references/stream/configuration.md +0 -151
- package/skills/cloudflare/references/stream/gotchas.md +0 -139
- package/skills/cloudflare/references/stream/patterns.md +0 -217
- package/skills/cloudflare/references/tail-workers/README.md +0 -92
- package/skills/cloudflare/references/tail-workers/api.md +0 -203
- package/skills/cloudflare/references/tail-workers/configuration.md +0 -178
- package/skills/cloudflare/references/tail-workers/gotchas.md +0 -206
- package/skills/cloudflare/references/tail-workers/patterns.md +0 -190
- package/skills/cloudflare/references/terraform/README.md +0 -100
- package/skills/cloudflare/references/terraform/api.md +0 -178
- package/skills/cloudflare/references/terraform/configuration.md +0 -197
- package/skills/cloudflare/references/terraform/gotchas.md +0 -150
- package/skills/cloudflare/references/terraform/patterns.md +0 -174
- package/skills/cloudflare/references/tunnel/README.md +0 -137
- package/skills/cloudflare/references/tunnel/api.md +0 -205
- package/skills/cloudflare/references/tunnel/configuration.md +0 -163
- package/skills/cloudflare/references/tunnel/gotchas.md +0 -159
- package/skills/cloudflare/references/tunnel/networking.md +0 -174
- package/skills/cloudflare/references/tunnel/patterns.md +0 -199
- package/skills/cloudflare/references/turn/README.md +0 -86
- package/skills/cloudflare/references/turn/api.md +0 -236
- package/skills/cloudflare/references/turn/configuration.md +0 -181
- package/skills/cloudflare/references/turn/gotchas.md +0 -236
- package/skills/cloudflare/references/turn/patterns.md +0 -228
- package/skills/cloudflare/references/turnstile/README.md +0 -102
- package/skills/cloudflare/references/turnstile/api.md +0 -253
- package/skills/cloudflare/references/turnstile/configuration.md +0 -242
- package/skills/cloudflare/references/turnstile/gotchas.md +0 -253
- package/skills/cloudflare/references/turnstile/patterns.md +0 -195
- package/skills/cloudflare/references/vectorize/README.md +0 -133
- package/skills/cloudflare/references/vectorize/api.md +0 -89
- package/skills/cloudflare/references/vectorize/configuration.md +0 -91
- package/skills/cloudflare/references/vectorize/gotchas.md +0 -83
- package/skills/cloudflare/references/vectorize/patterns.md +0 -92
- package/skills/cloudflare/references/waf/README.md +0 -125
- package/skills/cloudflare/references/waf/api.md +0 -203
- package/skills/cloudflare/references/waf/configuration.md +0 -215
- package/skills/cloudflare/references/waf/gotchas.md +0 -208
- package/skills/cloudflare/references/waf/patterns.md +0 -236
- package/skills/cloudflare/references/web-analytics/README.md +0 -149
- package/skills/cloudflare/references/web-analytics/configuration.md +0 -81
- package/skills/cloudflare/references/web-analytics/gotchas.md +0 -86
- package/skills/cloudflare/references/web-analytics/integration.md +0 -63
- package/skills/cloudflare/references/web-analytics/patterns.md +0 -98
- package/skills/cloudflare/references/workerd/README.md +0 -85
- package/skills/cloudflare/references/workerd/api.md +0 -219
- package/skills/cloudflare/references/workerd/configuration.md +0 -200
- package/skills/cloudflare/references/workerd/gotchas.md +0 -151
- package/skills/cloudflare/references/workerd/patterns.md +0 -205
- package/skills/cloudflare/references/workers/README.md +0 -110
- package/skills/cloudflare/references/workers/api.md +0 -197
- package/skills/cloudflare/references/workers/configuration.md +0 -184
- package/skills/cloudflare/references/workers/frameworks.md +0 -200
- package/skills/cloudflare/references/workers/gotchas.md +0 -145
- package/skills/cloudflare/references/workers/patterns.md +0 -220
- package/skills/cloudflare/references/workers-ai/README.md +0 -206
- package/skills/cloudflare/references/workers-ai/api.md +0 -115
- package/skills/cloudflare/references/workers-ai/configuration.md +0 -98
- package/skills/cloudflare/references/workers-ai/gotchas.md +0 -130
- package/skills/cloudflare/references/workers-ai/patterns.md +0 -122
- package/skills/cloudflare/references/workers-for-platforms/README.md +0 -95
- package/skills/cloudflare/references/workers-for-platforms/api.md +0 -212
- package/skills/cloudflare/references/workers-for-platforms/configuration.md +0 -178
- package/skills/cloudflare/references/workers-for-platforms/gotchas.md +0 -134
- package/skills/cloudflare/references/workers-for-platforms/patterns.md +0 -210
- package/skills/cloudflare/references/workers-playground/README.md +0 -131
- package/skills/cloudflare/references/workers-playground/api.md +0 -101
- package/skills/cloudflare/references/workers-playground/configuration.md +0 -169
- package/skills/cloudflare/references/workers-playground/gotchas.md +0 -88
- package/skills/cloudflare/references/workers-playground/patterns.md +0 -134
- package/skills/cloudflare/references/workers-vpc/README.md +0 -130
- package/skills/cloudflare/references/workers-vpc/api.md +0 -196
- package/skills/cloudflare/references/workers-vpc/configuration.md +0 -151
- package/skills/cloudflare/references/workers-vpc/gotchas.md +0 -171
- package/skills/cloudflare/references/workers-vpc/patterns.md +0 -235
- package/skills/cloudflare/references/workflows/README.md +0 -72
- package/skills/cloudflare/references/workflows/api.md +0 -237
- package/skills/cloudflare/references/workflows/configuration.md +0 -158
- package/skills/cloudflare/references/workflows/gotchas.md +0 -97
- package/skills/cloudflare/references/workflows/patterns.md +0 -245
- package/skills/cloudflare/references/wrangler/README.md +0 -143
- package/skills/cloudflare/references/wrangler/api.md +0 -188
- package/skills/cloudflare/references/wrangler/configuration.md +0 -198
- package/skills/cloudflare/references/wrangler/gotchas.md +0 -212
- package/skills/cloudflare/references/wrangler/patterns.md +0 -211
- package/skills/cloudflare/references/zaraz/IMPLEMENTATION_SUMMARY.md +0 -131
- package/skills/cloudflare/references/zaraz/README.md +0 -114
- package/skills/cloudflare/references/zaraz/api.md +0 -118
- package/skills/cloudflare/references/zaraz/configuration.md +0 -94
- package/skills/cloudflare/references/zaraz/gotchas.md +0 -88
- package/skills/cloudflare/references/zaraz/patterns.md +0 -77
- package/skills/docker/SKILL.md +0 -168
- package/skills/docker/references/advanced-examples.md +0 -71
- package/skills/docker/references/templates.md +0 -34
- package/skills/docs-marketer/SKILL.md +0 -178
- package/skills/docs-marketer/references/audit-categories.md +0 -328
- package/skills/docs-marketer/references/copilot-docs-prompts.md +0 -88
- package/skills/docs-marketer/references/copilot-usage.md +0 -16
- package/skills/docs-marketer/references/feedback-loop.md +0 -155
- package/skills/docs-marketer/references/multi-pass-docs-protocol.md +0 -410
- package/skills/drizzle-orm/SKILL.md +0 -82
- package/skills/durable-objects/SKILL.md +0 -167
- package/skills/durable-objects/references/advanced_features.md +0 -29
- package/skills/durable-objects/references/rules.md +0 -300
- package/skills/durable-objects/references/testing.md +0 -261
- package/skills/durable-objects/references/workers.md +0 -336
- package/skills/gcp/SKILL.md +0 -37
- package/skills/github-actions/SKILL.md +0 -262
- package/skills/github-actions/references/templates.md +0 -65
- package/skills/github-commander/SKILL.md +0 -144
- package/skills/github-commander/config/project-config.example.md +0 -125
- package/skills/github-commander/workflows/code-quality-audit.md +0 -82
- package/skills/github-commander/workflows/copilot-audit.md +0 -50
- package/skills/github-commander/workflows/issue-triage.md +0 -248
- package/skills/github-commander/workflows/milestone-sprint.md +0 -89
- package/skills/github-commander/workflows/perf-audit.md +0 -144
- package/skills/github-commander/workflows/pr-review.md +0 -129
- package/skills/github-commander/workflows/roadmap-kickoff.md +0 -79
- package/skills/github-commander/workflows/security-audit.md +0 -170
- package/skills/github-commander/workflows/update-deps.md +0 -109
- package/skills/github-copilot-cli/SKILL.md +0 -59
- package/skills/github-repo-setup/SKILL.md +0 -136
- package/skills/github-repo-setup/references/community-standards.md +0 -136
- package/skills/github-repo-setup/references/github-automation.md +0 -490
- package/skills/github-repo-setup/references/inline-templates.md +0 -205
- package/skills/github-repo-setup/references/project-config.md +0 -320
- package/skills/gitlab/SKILL.md +0 -120
- package/skills/gitlab/package-lock.json +0 -392
- package/skills/gitlab/package.json +0 -14
- package/skills/gitlab/scripts/gitlab-client.ts +0 -125
- package/skills/gitlab/scripts/gitlab-helper.ts +0 -80
- package/skills/golang/SKILL.md +0 -61
- package/skills/graphql/SKILL.md +0 -30
- package/skills/hono/SKILL.md +0 -82
- package/skills/journal-optimizer/SKILL.md +0 -206
- package/skills/journal-optimizer/references/optimizer-scripts.md +0 -169
- package/skills/llm-app-engineering/SKILL.md +0 -18
- package/skills/monorepo/SKILL.md +0 -56
- package/skills/multi-agent-orchestration/SKILL.md +0 -14
- package/skills/mysql/SKILL.md +0 -34
- package/skills/next-best-practices/README.md +0 -127
- package/skills/next-best-practices/SKILL.md +0 -86
- package/skills/next-best-practices/metadata.json +0 -17
- package/skills/next-best-practices/references/cache-components-examples.md +0 -234
- package/skills/next-best-practices/references/cache-components.md +0 -210
- package/skills/next-best-practices/references/upgrade-decision-tree.md +0 -33
- package/skills/next-best-practices/references/upgrade.md +0 -43
- package/skills/next-best-practices/rules/_sections.md +0 -46
- package/skills/next-best-practices/rules/_template.md +0 -28
- package/skills/next-best-practices/rules/advanced-event-handler-refs.md +0 -55
- package/skills/next-best-practices/rules/advanced-init-once.md +0 -42
- package/skills/next-best-practices/rules/advanced-use-latest.md +0 -39
- package/skills/next-best-practices/rules/async-api-routes.md +0 -35
- package/skills/next-best-practices/rules/async-defer-await.md +0 -80
- package/skills/next-best-practices/rules/async-dependencies.md +0 -48
- package/skills/next-best-practices/rules/async-parallel.md +0 -24
- package/skills/next-best-practices/rules/async-suspense-boundaries.md +0 -99
- package/skills/next-best-practices/rules/bundle-barrel-imports.md +0 -59
- package/skills/next-best-practices/rules/bundle-conditional.md +0 -37
- package/skills/next-best-practices/rules/bundle-defer-third-party.md +0 -48
- package/skills/next-best-practices/rules/bundle-dynamic-imports.md +0 -34
- package/skills/next-best-practices/rules/bundle-preload.md +0 -44
- package/skills/next-best-practices/rules/client-event-listeners.md +0 -78
- package/skills/next-best-practices/rules/client-localstorage-schema.md +0 -74
- package/skills/next-best-practices/rules/client-passive-event-listeners.md +0 -48
- package/skills/next-best-practices/rules/client-swr-dedup.md +0 -56
- package/skills/next-best-practices/rules/js-batch-dom-css.md +0 -110
- package/skills/next-best-practices/rules/js-cache-function-results.md +0 -80
- package/skills/next-best-practices/rules/js-cache-property-access.md +0 -28
- package/skills/next-best-practices/rules/js-cache-storage.md +0 -68
- package/skills/next-best-practices/rules/js-combine-iterations.md +0 -32
- package/skills/next-best-practices/rules/js-early-exit.md +0 -50
- package/skills/next-best-practices/rules/js-hoist-regexp.md +0 -45
- package/skills/next-best-practices/rules/js-index-maps.md +0 -37
- package/skills/next-best-practices/rules/js-length-check-first.md +0 -50
- package/skills/next-best-practices/rules/js-min-max-loop.md +0 -82
- package/skills/next-best-practices/rules/js-set-map-lookups.md +0 -24
- package/skills/next-best-practices/rules/js-tosorted-immutable.md +0 -57
- package/skills/next-best-practices/rules/rendering-activity.md +0 -24
- package/skills/next-best-practices/rules/rendering-animate-svg-wrapper.md +0 -38
- package/skills/next-best-practices/rules/rendering-conditional-render.md +0 -32
- package/skills/next-best-practices/rules/rendering-content-visibility.md +0 -38
- package/skills/next-best-practices/rules/rendering-hoist-jsx.md +0 -36
- package/skills/next-best-practices/rules/rendering-hydration-no-flicker.md +0 -72
- package/skills/next-best-practices/rules/rendering-hydration-suppress-warning.md +0 -26
- package/skills/next-best-practices/rules/rendering-svg-precision.md +0 -28
- package/skills/next-best-practices/rules/rendering-usetransition-loading.md +0 -75
- package/skills/next-best-practices/rules/rerender-defer-reads.md +0 -39
- package/skills/next-best-practices/rules/rerender-dependencies.md +0 -45
- package/skills/next-best-practices/rules/rerender-derived-state-no-effect.md +0 -40
- package/skills/next-best-practices/rules/rerender-derived-state.md +0 -29
- package/skills/next-best-practices/rules/rerender-functional-setstate.md +0 -77
- package/skills/next-best-practices/rules/rerender-lazy-state-init.md +0 -56
- package/skills/next-best-practices/rules/rerender-memo-with-default-value.md +0 -36
- package/skills/next-best-practices/rules/rerender-memo.md +0 -44
- package/skills/next-best-practices/rules/rerender-move-effect-to-event.md +0 -45
- package/skills/next-best-practices/rules/rerender-simple-expression-in-memo.md +0 -35
- package/skills/next-best-practices/rules/rerender-transitions.md +0 -40
- package/skills/next-best-practices/rules/rerender-use-ref-transient-values.md +0 -73
- package/skills/next-best-practices/rules/server-after-nonblocking.md +0 -73
- package/skills/next-best-practices/rules/server-auth-actions.md +0 -96
- package/skills/next-best-practices/rules/server-cache-lru.md +0 -41
- package/skills/next-best-practices/rules/server-cache-react.md +0 -76
- package/skills/next-best-practices/rules/server-dedup-props.md +0 -65
- package/skills/next-best-practices/rules/server-parallel-fetching.md +0 -83
- package/skills/next-best-practices/rules/server-serialization.md +0 -38
- package/skills/next-cache-components/SKILL.md +0 -441
- package/skills/next-upgrade/SKILL.md +0 -43
- package/skills/next-upgrade/references/decision-tree.md +0 -33
- package/skills/nodejs/SKILL.md +0 -46
- package/skills/opentelemetry/SKILL.md +0 -62
- package/skills/package.json +0 -89
- package/skills/playwright-standard/SKILL.md +0 -53
- package/skills/playwright-standard/examples/fixtures.ts +0 -66
- package/skills/playwright-standard/examples/type-stubs.d.ts +0 -10
- package/skills/playwright-standard/references/advanced-scenarios.md +0 -59
- package/skills/playwright-standard/references/infrastructure.md +0 -43
- package/skills/playwright-standard/references/locators.md +0 -7
- package/skills/postgres/SKILL.md +0 -38
- package/skills/python/SKILL.md +0 -195
- package/skills/python/references/advanced-patterns.md +0 -37
- package/skills/python/references/config-templates.md +0 -48
- package/skills/rag-pipelines/SKILL.md +0 -14
- package/skills/redis/SKILL.md +0 -31
- package/skills/render/SKILL.md +0 -35
- package/skills/rust/SKILL.md +0 -76
- package/skills/rust/references/borrow-checker.md +0 -13
- package/skills/rust/references/ecosystem.md +0 -11
- package/skills/sandbox-sdk/SKILL.md +0 -186
- package/skills/sandbox-sdk/references/api-quick-ref.md +0 -113
- package/skills/sandbox-sdk/references/examples.md +0 -52
- package/skills/shadcn-ui/SKILL.md +0 -37
- package/skills/skill-builder/SKILL.md +0 -56
- package/skills/skill-builder/checklist.md +0 -65
- package/skills/skill-builder/references/tutorial.md +0 -457
- package/skills/sqlite/SKILL.md +0 -49
- package/skills/table.md +0 -59
- package/skills/tailwind-css/SKILL.md +0 -219
- package/skills/tailwind-css/references/component-patterns.md +0 -52
- package/skills/trpc/SKILL.md +0 -56
- package/skills/typescript/SKILL.md +0 -50
- package/skills/typescript/assets/eslint-template.js +0 -102
- package/skills/typescript/assets/tsconfig-template.json +0 -45
- package/skills/typescript/references/enterprise-patterns.md +0 -531
- package/skills/typescript/references/generics.md +0 -493
- package/skills/typescript/references/nestjs-integration.md +0 -579
- package/skills/typescript/references/react-integration.md +0 -616
- package/skills/typescript/references/toolchain.md +0 -547
- package/skills/typescript/references/tutorial.md +0 -453
- package/skills/typescript/references/type-system.md +0 -481
- package/skills/vercel-ai-sdk/SKILL.md +0 -48
- package/skills/vitest-standard/SKILL.md +0 -76
- package/skills/vitest-standard/examples/service-mock.ts +0 -60
- package/skills/vitest-standard/examples/tdd-calculator.ts +0 -41
- package/skills/vitest-standard/examples/type-stubs.d.ts +0 -18
- package/skills/vitest-standard/references/assertions.md +0 -11
- package/skills/vitest-standard/references/async-and-errors.md +0 -58
- package/skills/vitest-standard/references/coverage-and-config.md +0 -53
- package/skills/vitest-standard/references/mocking.md +0 -61
- package/skills/vitest-standard/references/tdd-patterns.md +0 -60
- package/skills/web-perf/SKILL.md +0 -207
- package/skills/workers-best-practices/SKILL.md +0 -120
- package/skills/workers-best-practices/references/anti-patterns.md +0 -18
- package/skills/workers-best-practices/references/review.md +0 -174
- package/skills/workers-best-practices/references/rules.md +0 -485
- package/skills/wrangler/SKILL.md +0 -43
- package/skills/wrangler/references/cli-commands.md +0 -861
- package/skills/zod/SKILL.md +0 -48
package/dist/worker-script.js
CHANGED
|
@@ -1,415 +1,3010 @@
|
|
|
1
|
+
import { METHOD_ALIASES, VERSION, applyArgInterceptions } from './chunk-SGJU2DHU.js';
|
|
2
|
+
import { SIGNIFICANCE_TYPES, ENTRY_TYPES } from './chunk-D2FY6XS5.js';
|
|
1
3
|
import { parentPort } from 'worker_threads';
|
|
2
|
-
import * as
|
|
3
|
-
|
|
4
|
-
// src/codemode/worker-script.ts
|
|
4
|
+
import * as vm2 from 'vm';
|
|
5
5
|
|
|
6
6
|
// src/codemode/auto-return.ts
|
|
7
7
|
var NON_RETURNABLE = /^\s*(return|throw|const |let |var |if\b|else\b|for\b|while\b|do\b|switch\b|try\b|catch\b|finally\b|class |function |\/\/|\/\*|\{|\})/;
|
|
8
8
|
function transformAutoReturn(code) {
|
|
9
|
-
|
|
9
|
+
let trimmed = code.trimEnd();
|
|
10
10
|
if (!trimmed) return code;
|
|
11
|
+
while (trimmed.endsWith(";")) {
|
|
12
|
+
trimmed = trimmed.slice(0, -1).trimEnd();
|
|
13
|
+
}
|
|
14
|
+
let inString = null;
|
|
15
|
+
let isEscaped = false;
|
|
16
|
+
let lastBoundary = -1;
|
|
11
17
|
let depth = 0;
|
|
12
|
-
let
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
for (let i = 0; i < trimmed.length; i++) {
|
|
19
|
+
const ch = trimmed[i];
|
|
20
|
+
if (inString) {
|
|
21
|
+
if (ch === "\\") {
|
|
22
|
+
isEscaped = !isEscaped;
|
|
23
|
+
} else {
|
|
24
|
+
if (ch === inString && !isEscaped) {
|
|
25
|
+
inString = null;
|
|
26
|
+
}
|
|
27
|
+
isEscaped = false;
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
if (ch === "'" || ch === '"' || ch === "`") {
|
|
31
|
+
inString = ch;
|
|
32
|
+
} else if (ch === "{" || ch === "[" || ch === "(") {
|
|
33
|
+
depth++;
|
|
34
|
+
} else if (ch === "}" || ch === "]" || ch === ")") {
|
|
35
|
+
depth--;
|
|
36
|
+
} else if (depth === 0 && (ch === ";" || ch === "\n")) {
|
|
37
|
+
lastBoundary = i;
|
|
38
|
+
}
|
|
20
39
|
}
|
|
21
40
|
}
|
|
22
|
-
const lastStmt = (
|
|
41
|
+
const lastStmt = (lastBoundary >= 0 ? trimmed.slice(lastBoundary + 1) : trimmed).trim();
|
|
23
42
|
if (!lastStmt) return code;
|
|
24
43
|
if (NON_RETURNABLE.test(lastStmt)) return code;
|
|
25
|
-
if (
|
|
26
|
-
const before = trimmed.slice(0,
|
|
44
|
+
if (lastBoundary >= 0) {
|
|
45
|
+
const before = trimmed.slice(0, lastBoundary + 1);
|
|
27
46
|
return `${before}
|
|
28
47
|
return ${lastStmt}`;
|
|
29
48
|
}
|
|
30
49
|
return `return ${trimmed}`;
|
|
31
50
|
}
|
|
32
51
|
|
|
33
|
-
// src/codemode/worker-
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
// src/codemode/worker-result-proxy.ts
|
|
53
|
+
var RESULT_COLLECTION_KEYS = [
|
|
54
|
+
"entries",
|
|
55
|
+
"results",
|
|
56
|
+
"projects",
|
|
57
|
+
"items",
|
|
58
|
+
"rows",
|
|
59
|
+
"tables",
|
|
60
|
+
"flags",
|
|
61
|
+
"groups",
|
|
62
|
+
"users",
|
|
63
|
+
"capabilities",
|
|
64
|
+
"metrics",
|
|
65
|
+
"events",
|
|
66
|
+
"records",
|
|
67
|
+
"logs",
|
|
68
|
+
"aliases",
|
|
69
|
+
"tags",
|
|
70
|
+
"issues",
|
|
71
|
+
"pullRequests",
|
|
72
|
+
"milestones",
|
|
73
|
+
"columns",
|
|
74
|
+
"comments",
|
|
75
|
+
"files",
|
|
76
|
+
"errors",
|
|
77
|
+
"backups",
|
|
78
|
+
"deleted",
|
|
79
|
+
"updated",
|
|
80
|
+
"notFound",
|
|
81
|
+
"history",
|
|
82
|
+
"relationships",
|
|
83
|
+
"members",
|
|
84
|
+
"data"
|
|
85
|
+
];
|
|
86
|
+
var ITERATOR_COLLECTION_KEYS = [
|
|
87
|
+
"entries",
|
|
88
|
+
"results",
|
|
89
|
+
"projects",
|
|
90
|
+
"items",
|
|
91
|
+
"issues",
|
|
92
|
+
"pullRequests",
|
|
93
|
+
"milestones",
|
|
94
|
+
"columns",
|
|
95
|
+
"comments",
|
|
96
|
+
"files",
|
|
97
|
+
"errors",
|
|
98
|
+
"backups",
|
|
99
|
+
"deleted",
|
|
100
|
+
"updated",
|
|
101
|
+
"notFound",
|
|
102
|
+
"history",
|
|
103
|
+
"relationships",
|
|
104
|
+
"members"
|
|
105
|
+
];
|
|
106
|
+
var FAILED_ARRAY_METHODS = [
|
|
107
|
+
"find",
|
|
108
|
+
"map",
|
|
109
|
+
"filter",
|
|
110
|
+
"reduce",
|
|
111
|
+
"reduceRight",
|
|
112
|
+
"forEach",
|
|
113
|
+
"some",
|
|
114
|
+
"every",
|
|
115
|
+
"flatMap",
|
|
116
|
+
"includes",
|
|
117
|
+
"indexOf",
|
|
118
|
+
"findIndex",
|
|
119
|
+
"findLast",
|
|
120
|
+
"findLastIndex",
|
|
121
|
+
"join",
|
|
122
|
+
"at",
|
|
123
|
+
"concat",
|
|
124
|
+
"flat",
|
|
125
|
+
"with",
|
|
126
|
+
"slice"
|
|
127
|
+
];
|
|
128
|
+
var SUCCESS_ARRAY_METHODS = [
|
|
129
|
+
...FAILED_ARRAY_METHODS,
|
|
130
|
+
"keys",
|
|
131
|
+
"values",
|
|
132
|
+
"entries"
|
|
133
|
+
];
|
|
134
|
+
var MUTATOR_ARRAY_METHODS = [
|
|
135
|
+
"push",
|
|
136
|
+
"pop",
|
|
137
|
+
"shift",
|
|
138
|
+
"unshift",
|
|
139
|
+
"splice",
|
|
140
|
+
"sort",
|
|
141
|
+
"reverse",
|
|
142
|
+
"copyWithin",
|
|
143
|
+
"fill"
|
|
144
|
+
];
|
|
145
|
+
var ARRAY_SELF_ALIASES = [
|
|
146
|
+
"projects",
|
|
147
|
+
"entries",
|
|
148
|
+
"results",
|
|
149
|
+
"items",
|
|
150
|
+
"data",
|
|
151
|
+
"rows",
|
|
152
|
+
"relationships",
|
|
153
|
+
"members",
|
|
154
|
+
"tags",
|
|
155
|
+
"history",
|
|
156
|
+
"records"
|
|
157
|
+
];
|
|
158
|
+
var RESULT_LIST_ALIASES = [
|
|
159
|
+
"data",
|
|
160
|
+
"items",
|
|
161
|
+
"entries",
|
|
162
|
+
"results",
|
|
163
|
+
"rows",
|
|
164
|
+
"dataArray",
|
|
165
|
+
"projects",
|
|
166
|
+
"list",
|
|
167
|
+
"records"
|
|
168
|
+
];
|
|
169
|
+
var isObject = (val) => typeof val === "object" && val !== null && !Array.isArray(val);
|
|
170
|
+
var hasNumberId = (val) => isObject(val) && typeof val["id"] === "number";
|
|
171
|
+
var isDictLike = (obj) => {
|
|
172
|
+
const keys = Object.keys(obj).filter((k) => typeof k === "string" && !k.startsWith("_"));
|
|
173
|
+
return keys.length > 0 && !keys.includes("error") && !keys.includes("success");
|
|
174
|
+
};
|
|
175
|
+
var dictToItems = (obj) => Object.entries(obj).filter(([k]) => typeof k === "string" && !k.startsWith("_")).map(([key, item]) => {
|
|
176
|
+
if (isObject(item)) {
|
|
177
|
+
const name = typeof item["name"] === "string" && item["name"].length > 0 ? item["name"] : key;
|
|
178
|
+
const desc = typeof item["description"] === "string" ? item["description"] : "";
|
|
179
|
+
const projNum = item["project_number"] ?? item["id"] ?? item["projectNumber"];
|
|
180
|
+
return { ...item, name, description: desc, project_number: projNum, projectNumber: projNum };
|
|
181
|
+
}
|
|
182
|
+
return { name: key, description: "", value: item };
|
|
183
|
+
});
|
|
184
|
+
function findPrimaryArrayKey(targetRecord, keysToCheck = RESULT_COLLECTION_KEYS) {
|
|
185
|
+
const arrayKeys = Object.keys(targetRecord).filter((k) => Array.isArray(targetRecord[k]));
|
|
186
|
+
const matched = arrayKeys.find((k) => keysToCheck.includes(k));
|
|
187
|
+
if (matched !== void 0) return matched;
|
|
188
|
+
return arrayKeys.length === 1 ? arrayKeys[0] : void 0;
|
|
189
|
+
}
|
|
190
|
+
function bindArrayMethod(arr, prop) {
|
|
191
|
+
const method = Reflect.get(arr, prop);
|
|
192
|
+
if (typeof method === "function") {
|
|
193
|
+
return (...args) => method.apply(arr, args);
|
|
194
|
+
}
|
|
195
|
+
return void 0;
|
|
48
196
|
}
|
|
49
197
|
function wrapResult(result) {
|
|
50
|
-
if (result
|
|
51
|
-
|
|
52
|
-
|
|
198
|
+
if (result === null || result === void 0 || typeof result !== "object") {
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
if ("success" in result && Reflect.get(result, "success") === false) {
|
|
202
|
+
return new Proxy(result, {
|
|
203
|
+
ownKeys: (target) => Reflect.ownKeys(target),
|
|
204
|
+
getOwnPropertyDescriptor: (target, prop) => Reflect.getOwnPropertyDescriptor(target, prop),
|
|
53
205
|
get(target, prop) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
206
|
+
const errVal = Reflect.get(target, "error");
|
|
207
|
+
const codeVal = Reflect.get(target, "code");
|
|
208
|
+
if (prop === "error" && typeof errVal === "string" && typeof codeVal === "string") {
|
|
209
|
+
return `[${codeVal}] ${errVal}`;
|
|
210
|
+
}
|
|
211
|
+
if (prop in target) return Reflect.get(target, prop);
|
|
212
|
+
if (prop === "length") return 0;
|
|
213
|
+
if (typeof prop === "string" && /^\d+$/.test(prop)) return void 0;
|
|
214
|
+
if (prop === Symbol.iterator) return function* () {
|
|
215
|
+
yield* [];
|
|
216
|
+
};
|
|
217
|
+
if (typeof prop === "string" && RESULT_COLLECTION_KEYS.includes(prop)) return [];
|
|
218
|
+
if (typeof prop === "string" && FAILED_ARRAY_METHODS.includes(prop)) return () => [];
|
|
219
|
+
return void 0;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
if (Array.isArray(result)) {
|
|
224
|
+
const arr = result;
|
|
225
|
+
return new Proxy(arr, {
|
|
226
|
+
ownKeys: (target) => Reflect.ownKeys(target),
|
|
227
|
+
getOwnPropertyDescriptor: (target, prop) => Reflect.getOwnPropertyDescriptor(target, prop),
|
|
228
|
+
get(target, prop, receiver) {
|
|
229
|
+
if (prop in target) {
|
|
230
|
+
const val = Reflect.get(target, prop, receiver);
|
|
231
|
+
return typeof val === "function" ? val.bind(target) : val;
|
|
61
232
|
}
|
|
233
|
+
if (prop === "success") return true;
|
|
234
|
+
if (typeof prop === "string" && ARRAY_SELF_ALIASES.includes(prop)) return receiver;
|
|
62
235
|
return void 0;
|
|
63
236
|
}
|
|
64
237
|
});
|
|
65
238
|
}
|
|
66
|
-
return result
|
|
239
|
+
return new Proxy(result, {
|
|
240
|
+
ownKeys: (target) => Reflect.ownKeys(target),
|
|
241
|
+
getOwnPropertyDescriptor: (target, prop) => Reflect.getOwnPropertyDescriptor(target, prop),
|
|
242
|
+
get(target, prop, receiver) {
|
|
243
|
+
if (prop in target) {
|
|
244
|
+
const val = Reflect.get(target, prop);
|
|
245
|
+
return val !== null && typeof val === "object" && !Array.isArray(val) ? wrapResult(val) : val;
|
|
246
|
+
}
|
|
247
|
+
if (!isObject(target)) return void 0;
|
|
248
|
+
const targetRecord = target;
|
|
249
|
+
if (prop === "hasMore") {
|
|
250
|
+
if ("next_cursor" in targetRecord && targetRecord["next_cursor"] !== null && targetRecord["next_cursor"] !== void 0 && targetRecord["next_cursor"] !== "") {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
if ("entries" in targetRecord || "results" in targetRecord || "items" in targetRecord) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if ((prop === "statistics" || prop === "stats") && !("statistics" in targetRecord) && !("stats" in targetRecord) && ("totalEntries" in targetRecord || "entriesByType" in targetRecord)) {
|
|
258
|
+
return receiver;
|
|
259
|
+
}
|
|
260
|
+
if (prop === "total" || prop === "totalCount" || prop === "total_entries" || prop === "totalEntries") {
|
|
261
|
+
if ("count" in targetRecord && typeof targetRecord["count"] === "number") return targetRecord["count"];
|
|
262
|
+
if ("totalEntries" in targetRecord && typeof targetRecord["totalEntries"] === "number") {
|
|
263
|
+
return targetRecord["totalEntries"];
|
|
264
|
+
}
|
|
265
|
+
if ("total" in targetRecord && typeof targetRecord["total"] === "number") return targetRecord["total"];
|
|
266
|
+
const targetKey = findPrimaryArrayKey(targetRecord, [
|
|
267
|
+
"entries",
|
|
268
|
+
"results",
|
|
269
|
+
"projects",
|
|
270
|
+
"items",
|
|
271
|
+
"rows",
|
|
272
|
+
"records"
|
|
273
|
+
]);
|
|
274
|
+
if (targetKey !== void 0 && Array.isArray(targetRecord[targetKey])) {
|
|
275
|
+
return targetRecord[targetKey].length;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const entryObj = targetRecord["entry"];
|
|
279
|
+
if ((prop === "id" || prop === "entryId") && isObject(entryObj) && "id" in entryObj) {
|
|
280
|
+
return entryObj["id"];
|
|
281
|
+
}
|
|
282
|
+
const projObj = targetRecord["project"];
|
|
283
|
+
if (isObject(projObj)) {
|
|
284
|
+
if (prop === "project_number" && ("project_number" in projObj || "id" in projObj)) {
|
|
285
|
+
return projObj["project_number"] ?? projObj["id"];
|
|
286
|
+
}
|
|
287
|
+
if ((prop === "name" || prop === "project_name") && "name" in projObj) return projObj["name"];
|
|
288
|
+
if (typeof prop === "string" && prop in projObj) return projObj[prop];
|
|
289
|
+
}
|
|
290
|
+
if (prop === "entryIds" && "entries" in targetRecord && Array.isArray(targetRecord["entries"])) {
|
|
291
|
+
return targetRecord["entries"].filter(hasNumberId).map((e) => e.id);
|
|
292
|
+
}
|
|
293
|
+
if (prop === "entryIds" && "updated" in targetRecord && Array.isArray(targetRecord["updated"])) {
|
|
294
|
+
return targetRecord["updated"].filter(hasNumberId).map((e) => e.id);
|
|
295
|
+
}
|
|
296
|
+
if (prop === "deletedIds" && "deleted" in targetRecord && Array.isArray(targetRecord["deleted"])) {
|
|
297
|
+
return targetRecord["deleted"];
|
|
298
|
+
}
|
|
299
|
+
if (prop === "deletedCount" && "count" in targetRecord && typeof targetRecord["count"] === "number") {
|
|
300
|
+
return targetRecord["count"];
|
|
301
|
+
}
|
|
302
|
+
if (prop === "revisions" && "history" in targetRecord && Array.isArray(targetRecord["history"])) {
|
|
303
|
+
return targetRecord["history"].filter(isObject).map(
|
|
304
|
+
(h) => new Proxy(h, {
|
|
305
|
+
get(t, p) {
|
|
306
|
+
if (p === "revisionNumber") return t["revisionId"];
|
|
307
|
+
if (p === "contentSnapshot") return t["content"];
|
|
308
|
+
return typeof p === "string" ? t[p] : void 0;
|
|
309
|
+
}
|
|
310
|
+
})
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
if (prop === Symbol.iterator) {
|
|
314
|
+
const targetKey = findPrimaryArrayKey(targetRecord, ITERATOR_COLLECTION_KEYS);
|
|
315
|
+
if (targetKey !== void 0 && Array.isArray(targetRecord[targetKey])) {
|
|
316
|
+
const arrToYield = targetRecord[targetKey];
|
|
317
|
+
return function* () {
|
|
318
|
+
yield* arrToYield;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
if ("project" in targetRecord && isObject(targetRecord["project"])) {
|
|
322
|
+
const proj = targetRecord["project"];
|
|
323
|
+
return function* () {
|
|
324
|
+
yield proj;
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
if ("projects" in targetRecord && isObject(targetRecord["projects"])) {
|
|
328
|
+
const items = dictToItems(targetRecord["projects"]);
|
|
329
|
+
return function* () {
|
|
330
|
+
yield* items;
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
if (isDictLike(targetRecord)) {
|
|
334
|
+
const items = dictToItems(targetRecord);
|
|
335
|
+
return function* () {
|
|
336
|
+
yield* items;
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (typeof prop === "string" && RESULT_LIST_ALIASES.includes(prop)) {
|
|
341
|
+
const targetKey = findPrimaryArrayKey(targetRecord);
|
|
342
|
+
if (targetKey !== void 0) return targetRecord[targetKey];
|
|
343
|
+
if ("projects" in targetRecord && isObject(targetRecord["projects"])) {
|
|
344
|
+
return wrapResult(dictToItems(targetRecord["projects"]));
|
|
345
|
+
}
|
|
346
|
+
if (isDictLike(targetRecord)) return wrapResult(dictToItems(targetRecord));
|
|
347
|
+
if ("project" in targetRecord && isObject(targetRecord["project"])) {
|
|
348
|
+
return wrapResult([targetRecord["project"]]);
|
|
349
|
+
}
|
|
350
|
+
if ("entry" in targetRecord && isObject(targetRecord["entry"])) {
|
|
351
|
+
return wrapResult([targetRecord["entry"]]);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (prop === "result") return receiver;
|
|
355
|
+
if (prop === "length") {
|
|
356
|
+
const targetKey = findPrimaryArrayKey(targetRecord);
|
|
357
|
+
if (targetKey !== void 0 && Array.isArray(targetRecord[targetKey])) {
|
|
358
|
+
return targetRecord[targetKey].length;
|
|
359
|
+
}
|
|
360
|
+
if ("project" in targetRecord && isObject(targetRecord["project"])) return 1;
|
|
361
|
+
if ("projects" in targetRecord && isObject(targetRecord["projects"])) {
|
|
362
|
+
return Object.keys(targetRecord["projects"]).length;
|
|
363
|
+
}
|
|
364
|
+
if (isDictLike(targetRecord)) return Object.keys(targetRecord).length;
|
|
365
|
+
}
|
|
366
|
+
if (typeof prop === "string" && /^\d+$/.test(prop)) {
|
|
367
|
+
const idx = parseInt(prop, 10);
|
|
368
|
+
if ("project" in targetRecord && isObject(targetRecord["project"]) && idx === 0) {
|
|
369
|
+
return targetRecord["project"];
|
|
370
|
+
}
|
|
371
|
+
const targetKey = findPrimaryArrayKey(targetRecord);
|
|
372
|
+
if (targetKey !== void 0 && Array.isArray(targetRecord[targetKey])) {
|
|
373
|
+
return targetRecord[targetKey][idx];
|
|
374
|
+
}
|
|
375
|
+
if ("projects" in targetRecord && isObject(targetRecord["projects"])) {
|
|
376
|
+
return dictToItems(targetRecord["projects"])[idx];
|
|
377
|
+
}
|
|
378
|
+
if (isDictLike(targetRecord)) return dictToItems(targetRecord)[idx];
|
|
379
|
+
}
|
|
380
|
+
if (typeof prop === "string" && SUCCESS_ARRAY_METHODS.includes(prop)) {
|
|
381
|
+
const targetKey = findPrimaryArrayKey(targetRecord);
|
|
382
|
+
if (targetKey !== void 0 && Array.isArray(targetRecord[targetKey])) {
|
|
383
|
+
const bound = bindArrayMethod(targetRecord[targetKey], prop);
|
|
384
|
+
if (bound !== void 0) return bound;
|
|
385
|
+
}
|
|
386
|
+
if ("project" in targetRecord && isObject(targetRecord["project"])) {
|
|
387
|
+
const bound = bindArrayMethod([targetRecord["project"]], prop);
|
|
388
|
+
if (bound !== void 0) return bound;
|
|
389
|
+
}
|
|
390
|
+
if ("projects" in targetRecord && isObject(targetRecord["projects"])) {
|
|
391
|
+
const bound = bindArrayMethod(dictToItems(targetRecord["projects"]), prop);
|
|
392
|
+
if (bound !== void 0) return bound;
|
|
393
|
+
}
|
|
394
|
+
if (isDictLike(targetRecord)) {
|
|
395
|
+
const bound = bindArrayMethod(dictToItems(targetRecord), prop);
|
|
396
|
+
if (bound !== void 0) return bound;
|
|
397
|
+
}
|
|
398
|
+
const keys = Object.keys(target).join(", ") || "none";
|
|
399
|
+
throw new TypeError(
|
|
400
|
+
`\u{1F6E0}\uFE0F AUTONOMOUS HEALING: CodeMode Non-Array Proxy Error: Attempted to call Array method '${prop}' on an Object. The returned result is not an Array, and no array properties could be automatically resolved. Check the available keys and access the correct array property. Keys available: ${keys}`
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
if (typeof prop === "string" && MUTATOR_ARRAY_METHODS.includes(prop)) {
|
|
404
|
+
throw new Error(
|
|
405
|
+
`\u{1F6E0}\uFE0F AUTONOMOUS HEALING: [VALIDATION_ERROR] CodeMode Proxy Error: Array mutator method '${prop}' is not allowed on API results. Modifying local arrays does not update the server state. You MUST use the appropriate API tool (e.g., mj.core.updateEntry, mj.admin.batchUpdateEntries) to persist changes.`
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
return void 0;
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// src/codemode/proxy-helpers.ts
|
|
414
|
+
function wrapPromise(promise, methodName) {
|
|
415
|
+
return new Proxy(promise, {
|
|
416
|
+
get(target, prop) {
|
|
417
|
+
if (prop === "then") return target.then.bind(target);
|
|
418
|
+
if (prop === "catch") return target.catch.bind(target);
|
|
419
|
+
if (prop === "finally") return target.finally.bind(target);
|
|
420
|
+
if (typeof prop === "string" && !["constructor", "toString", "valueOf", "toJSON"].includes(prop)) {
|
|
421
|
+
if (["prepare", "exec", "query", "run"].includes(prop)) {
|
|
422
|
+
throw new Error(
|
|
423
|
+
`\u{1F6E0}\uFE0F AUTONOMOUS HEALING: Attempted to call database method '${prop}' on an unresolved Promise. In Code Mode, avoid direct database driver methods and use high-level mj.* API methods (e.g. mj.admin.updateEntry, mj.core.createEntry), or await the tool call.`
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
throw new Error(
|
|
427
|
+
`\u{1F6E0}\uFE0F AUTONOMOUS HEALING: Attempted to access property '${prop}' on a Promise object. Did you forget to 'await' the tool call? (e.g. const result = await mj.group.${methodName}(...))`
|
|
428
|
+
);
|
|
429
|
+
}
|
|
430
|
+
if (prop === Symbol.iterator) {
|
|
431
|
+
throw new Error(
|
|
432
|
+
`\u{1F6E0}\uFE0F AUTONOMOUS HEALING: Attempted to iterate over a Promise object. Did you forget to 'await' the tool call? (e.g. const [item] = await mj.group.${methodName}(...))`
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
return Reflect.get(target, prop);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
function attachMethodIntrospection(targetFn, group, methodName, getSchema, customDescription) {
|
|
440
|
+
const description = customDescription ?? `Code Mode tool mj.${group}.${methodName}. Use mj.${group}.${methodName}.schema() to view parameter schema.`;
|
|
441
|
+
const getInfo = () => Promise.resolve({ name: methodName, group, schema: getSchema(), description });
|
|
442
|
+
Object.assign(targetFn, {
|
|
443
|
+
schema: () => Promise.resolve(getSchema()),
|
|
444
|
+
help: getInfo,
|
|
445
|
+
describe: getInfo
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
function createGetConfigInterceptor() {
|
|
449
|
+
return () => wrapPromise(
|
|
450
|
+
Promise.resolve(
|
|
451
|
+
wrapResult({
|
|
452
|
+
success: false,
|
|
453
|
+
error: "Code Mode cannot directly read configuration via getConfig(). Use mj.core.listProjects() to discover active projects, or updateConfiguration() to change settings.",
|
|
454
|
+
code: "VALIDATION_ERROR",
|
|
455
|
+
category: "validation",
|
|
456
|
+
recoverable: true
|
|
457
|
+
})
|
|
458
|
+
),
|
|
459
|
+
"getConfig"
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
function createGetBriefingInterceptor() {
|
|
463
|
+
return () => wrapPromise(
|
|
464
|
+
Promise.resolve(
|
|
465
|
+
wrapResult({
|
|
466
|
+
success: false,
|
|
467
|
+
error: "Code Mode cannot directly read the briefing resource via getBriefing(). Use mj.core.getRecentEntries() instead, or read the memory://briefing resource via standard MCP client requests outside of Code Mode.",
|
|
468
|
+
code: "VALIDATION_ERROR",
|
|
469
|
+
category: "validation",
|
|
470
|
+
recoverable: true
|
|
471
|
+
})
|
|
472
|
+
),
|
|
473
|
+
"getBriefing"
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
var RESOURCE_SUGGESTIONS = {
|
|
477
|
+
"memory://recent": "mj.core.getRecentEntries()",
|
|
478
|
+
"memory://statistics": "mj.analytics.getStatistics()",
|
|
479
|
+
"memory://tags": "mj.core.listTags()",
|
|
480
|
+
"memory://flags": 'mj.team.teamListFlags({ status: "active" })',
|
|
481
|
+
"memory://significant": 'mj.search.searchEntries({ sort_by: "importance" })',
|
|
482
|
+
"memory://insights": "mj.analytics.getCrossProjectInsights()"
|
|
483
|
+
};
|
|
484
|
+
function createReadResourceInterceptor() {
|
|
485
|
+
return (uri) => {
|
|
486
|
+
let hint = "";
|
|
487
|
+
if (typeof uri === "string") {
|
|
488
|
+
const match = Object.entries(RESOURCE_SUGGESTIONS).find(([k]) => uri.startsWith(k));
|
|
489
|
+
if (match !== void 0) hint = ` Try: ${match[1]}`;
|
|
490
|
+
}
|
|
491
|
+
return wrapPromise(
|
|
492
|
+
Promise.resolve(
|
|
493
|
+
wrapResult({
|
|
494
|
+
success: false,
|
|
495
|
+
error: `Code Mode cannot directly read MCP resources (e.g., memory://briefing) using readResource().${hint} Use the appropriate mj.* tools to query data, or read the resource via standard MCP client requests outside of Code Mode.`,
|
|
496
|
+
code: "VALIDATION_ERROR",
|
|
497
|
+
category: "validation",
|
|
498
|
+
recoverable: true
|
|
499
|
+
})
|
|
500
|
+
),
|
|
501
|
+
"readResource"
|
|
502
|
+
);
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
function createFactoryFnProxy(api) {
|
|
506
|
+
const factoryFn = function(..._args) {
|
|
507
|
+
return api;
|
|
508
|
+
};
|
|
509
|
+
return new Proxy(factoryFn, {
|
|
510
|
+
apply: () => api,
|
|
511
|
+
construct: () => api,
|
|
512
|
+
get(_t, p) {
|
|
513
|
+
if (p === "then") return void 0;
|
|
514
|
+
if (p === "name") return "factoryFn";
|
|
515
|
+
if (p === "length") return 0;
|
|
516
|
+
if (p === "bind" || p === "call" || p === "apply" || p === "toString") {
|
|
517
|
+
return Function.prototype[p].bind(factoryFn);
|
|
518
|
+
}
|
|
519
|
+
return typeof p === "string" ? api[p] : void 0;
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
function createUnknownGroupRejectionProxy(prop, reason) {
|
|
524
|
+
return new Proxy(() => void 0, {
|
|
525
|
+
apply() {
|
|
526
|
+
return wrapPromise(
|
|
527
|
+
Promise.resolve(
|
|
528
|
+
wrapResult({
|
|
529
|
+
success: false,
|
|
530
|
+
error: reason,
|
|
531
|
+
code: "VALIDATION_ERROR",
|
|
532
|
+
category: "validation",
|
|
533
|
+
recoverable: true
|
|
534
|
+
})
|
|
535
|
+
),
|
|
536
|
+
prop
|
|
537
|
+
);
|
|
538
|
+
},
|
|
539
|
+
get(_t, subProp) {
|
|
540
|
+
if (typeof subProp === "symbol" || subProp === "then") return void 0;
|
|
541
|
+
return (..._args) => wrapPromise(
|
|
542
|
+
Promise.resolve(
|
|
543
|
+
wrapResult({
|
|
544
|
+
success: false,
|
|
545
|
+
error: `${reason} (Attempted to access 'mj.${prop}.${subProp}')`,
|
|
546
|
+
code: "VALIDATION_ERROR",
|
|
547
|
+
category: "validation",
|
|
548
|
+
recoverable: true
|
|
549
|
+
})
|
|
550
|
+
),
|
|
551
|
+
`${prop}.${subProp}`
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// src/codemode/proxy-namespaces.ts
|
|
558
|
+
var TABLES = [
|
|
559
|
+
"memory_journal",
|
|
560
|
+
"tags",
|
|
561
|
+
"entry_tags",
|
|
562
|
+
"relationships",
|
|
563
|
+
"entry_anchors",
|
|
564
|
+
"entry_revisions",
|
|
565
|
+
"vec_embeddings",
|
|
566
|
+
"team_flags"
|
|
567
|
+
];
|
|
568
|
+
function createSchemaProxy(safeRpcCall) {
|
|
569
|
+
const schemaHelp = () => Promise.resolve({
|
|
570
|
+
group: "schema",
|
|
571
|
+
description: "Memory Journal Schema: Embedded SQLite database storing journal entries, tags, relationships, code anchors, revisions, vector embeddings, and team flags.",
|
|
572
|
+
tables: TABLES,
|
|
573
|
+
entrySchema: {
|
|
574
|
+
id: "number (auto-increment primary key)",
|
|
575
|
+
content: "string (required, markdown body)",
|
|
576
|
+
entry_type: ENTRY_TYPES.map((t) => `'${t}'`).join(" | "),
|
|
577
|
+
timestamp: "string (ISO 8601 timestamp)",
|
|
578
|
+
is_personal: "boolean (default: true)",
|
|
579
|
+
significance_type: `optional (${SIGNIFICANCE_TYPES.map((t) => `'${t}'`).join(" | ")})`,
|
|
580
|
+
tags: "string[] (optional array of kebab-case tags)",
|
|
581
|
+
workspace_id: "string (required repository/workspace identifier)",
|
|
582
|
+
project_number: "number (optional GitHub project number)",
|
|
583
|
+
impact_score: "number (0.0-1.0 blast radius score)",
|
|
584
|
+
trust_score: "number (0.0-1.0 confidence score)",
|
|
585
|
+
validation_status: "'passed' | 'none' | 'failed'",
|
|
586
|
+
auto_context: 'string (optional JSON metadata string, e.g. { "commits": ["<sha>"] })',
|
|
587
|
+
session_id: "string (optional session tracking id)",
|
|
588
|
+
relationships: "Array<{ targetId: number, relationType?: string }> (optional entry links)",
|
|
589
|
+
anchors: "Array<{ anchor_path: string, anchor_type: string, status?: string }> (optional code anchors)"
|
|
590
|
+
},
|
|
591
|
+
methods: ["help", "describe", "listTables", "describeTable", "getSchema"],
|
|
592
|
+
usage: "Use mj.core.createEntry.schema() for entry parameter details, or mj.analytics.getStatistics() for database statistics."
|
|
593
|
+
});
|
|
594
|
+
const schemaCallable = (..._args) => safeRpcCall("analytics", "get_statistics", []).then(wrapResult);
|
|
595
|
+
return new Proxy(schemaCallable, {
|
|
596
|
+
apply: (_t, _thisArg, args) => safeRpcCall("analytics", "get_statistics", args).then(wrapResult),
|
|
597
|
+
get(_t, p) {
|
|
598
|
+
if (typeof p === "symbol" || p === "then") return void 0;
|
|
599
|
+
if (p === "help" || p === "describe" || p === "describeTable" || p === "getSchema") return schemaHelp;
|
|
600
|
+
if (p === "listTables") return () => Promise.resolve({ success: true, tables: TABLES });
|
|
601
|
+
if (p === "tables") return TABLES;
|
|
602
|
+
if (p in Function.prototype) return Reflect.get(Function.prototype, p);
|
|
603
|
+
return void 0;
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
function createProjectsProxy(methods, invokeRpc) {
|
|
608
|
+
const adminListProjects = methods["admin"]?.includes("list_projects") ? (...args) => invokeRpc("admin", "list_projects", args) : methods["analytics"]?.includes("get_cross_project_insights") ? (...args) => invokeRpc("analytics", "get_cross_project_insights", args) : () => wrapPromise(Promise.resolve(wrapResult({ success: true, projects: {}, items: [], data: [] })), "list_projects");
|
|
609
|
+
const adminGetProject = methods["admin"]?.includes("get_project") ? (nameOrParams) => {
|
|
610
|
+
const params = typeof nameOrParams === "string" || typeof nameOrParams === "number" ? [{ name: String(nameOrParams) }] : [nameOrParams ?? {}];
|
|
611
|
+
return invokeRpc("admin", "get_project", params);
|
|
612
|
+
} : () => wrapPromise(Promise.resolve(wrapResult({ success: true })), "get_project");
|
|
613
|
+
const adminRegisterProject = methods["admin"]?.includes("register_project") ? (...args) => invokeRpc("admin", "register_project", args) : () => wrapPromise(Promise.resolve(wrapResult({ success: true })), "register_project");
|
|
614
|
+
const adminUpdateProject = methods["admin"]?.includes("update_project") ? (...args) => invokeRpc("admin", "update_project", args) : () => wrapPromise(Promise.resolve(wrapResult({ success: true })), "update_project");
|
|
615
|
+
const adminDeleteProject = methods["admin"]?.includes("delete_project") ? (...args) => invokeRpc("admin", "delete_project", args) : () => wrapPromise(Promise.resolve(wrapResult({ success: true })), "delete_project");
|
|
616
|
+
const projectsCallable = (...args) => adminListProjects(...args);
|
|
617
|
+
Object.assign(projectsCallable, {
|
|
618
|
+
list: adminListProjects,
|
|
619
|
+
listProjects: adminListProjects,
|
|
620
|
+
list_projects: adminListProjects,
|
|
621
|
+
getProjects: adminListProjects,
|
|
622
|
+
get_projects: adminListProjects,
|
|
623
|
+
getAll: adminListProjects,
|
|
624
|
+
all: adminListProjects,
|
|
625
|
+
get: adminGetProject,
|
|
626
|
+
getProject: adminGetProject,
|
|
627
|
+
get_project: adminGetProject,
|
|
628
|
+
find: adminGetProject,
|
|
629
|
+
findProject: adminGetProject,
|
|
630
|
+
find_project: adminGetProject,
|
|
631
|
+
register: adminRegisterProject,
|
|
632
|
+
registerProject: adminRegisterProject,
|
|
633
|
+
register_project: adminRegisterProject,
|
|
634
|
+
create: adminRegisterProject,
|
|
635
|
+
createProject: adminRegisterProject,
|
|
636
|
+
update: adminUpdateProject,
|
|
637
|
+
updateProject: adminUpdateProject,
|
|
638
|
+
update_project: adminUpdateProject,
|
|
639
|
+
delete: adminDeleteProject,
|
|
640
|
+
deleteProject: adminDeleteProject,
|
|
641
|
+
delete_project: adminDeleteProject,
|
|
642
|
+
remove: adminDeleteProject,
|
|
643
|
+
removeProject: adminDeleteProject
|
|
644
|
+
});
|
|
645
|
+
return new Proxy(projectsCallable, {
|
|
646
|
+
apply: (_t, _thisArg, args) => adminListProjects(...args),
|
|
647
|
+
get(t, p) {
|
|
648
|
+
if (typeof p === "symbol" || p === "then") return void 0;
|
|
649
|
+
if (p in t) return Reflect.get(t, p);
|
|
650
|
+
if (typeof p === "string") {
|
|
651
|
+
const low = p.toLowerCase();
|
|
652
|
+
if (low.includes("list") || low.includes("all") || low.includes("get") && low.endsWith("s")) {
|
|
653
|
+
return adminListProjects;
|
|
654
|
+
}
|
|
655
|
+
if (low.includes("get") || low.includes("find")) return adminGetProject;
|
|
656
|
+
if (low.includes("create") || low.includes("register") || low.includes("add")) return adminRegisterProject;
|
|
657
|
+
if (low.includes("update") || low.includes("edit")) return adminUpdateProject;
|
|
658
|
+
if (low.includes("delete") || low.includes("remove")) return adminDeleteProject;
|
|
659
|
+
}
|
|
660
|
+
return adminListProjects;
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
function createTagsProxy(methods, invokeRpc) {
|
|
665
|
+
const coreListTags = methods["core"]?.includes("list_tags") ? (...args) => invokeRpc("core", "list_tags", args) : () => wrapPromise(Promise.resolve(wrapResult({ success: true, tags: [], count: 0 })), "list_tags");
|
|
666
|
+
const adminMergeTags = methods["admin"]?.includes("merge_tags") ? (...args) => invokeRpc("admin", "merge_tags", args) : () => wrapPromise(Promise.resolve(wrapResult({ success: true })), "merge_tags");
|
|
667
|
+
const tagsCallable = (...args) => coreListTags(...args);
|
|
668
|
+
Object.assign(tagsCallable, {
|
|
669
|
+
list: coreListTags,
|
|
670
|
+
listTags: coreListTags,
|
|
671
|
+
list_tags: coreListTags,
|
|
672
|
+
get: coreListTags,
|
|
673
|
+
getTags: coreListTags,
|
|
674
|
+
get_tags: coreListTags,
|
|
675
|
+
getAll: coreListTags,
|
|
676
|
+
all: coreListTags,
|
|
677
|
+
merge: adminMergeTags,
|
|
678
|
+
mergeTags: adminMergeTags,
|
|
679
|
+
merge_tags: adminMergeTags
|
|
680
|
+
});
|
|
681
|
+
return new Proxy(tagsCallable, {
|
|
682
|
+
apply: (_t, _thisArg, args) => coreListTags(...args),
|
|
683
|
+
get(t, p) {
|
|
684
|
+
if (typeof p === "symbol" || p === "then") return void 0;
|
|
685
|
+
if (p in t) return Reflect.get(t, p);
|
|
686
|
+
if (typeof p === "string" && p.toLowerCase().includes("merge")) return adminMergeTags;
|
|
687
|
+
return coreListTags;
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
function createSystemProxy(methods, invokeRpc) {
|
|
692
|
+
const getStats = methods["analytics"]?.includes("get_statistics") ? (...args) => invokeRpc("analytics", "get_statistics", args) : () => wrapPromise(Promise.resolve(wrapResult({ success: true })), "get_statistics");
|
|
693
|
+
const systemCallable = (...args) => getStats(...args);
|
|
694
|
+
const statsKeys = [
|
|
695
|
+
"getStatistics",
|
|
696
|
+
"getStats",
|
|
697
|
+
"stats",
|
|
698
|
+
"serverInfo",
|
|
699
|
+
"server_info",
|
|
700
|
+
"serverHealth",
|
|
701
|
+
"server_health",
|
|
702
|
+
"serverStatus",
|
|
703
|
+
"server_status",
|
|
704
|
+
"healthCheck",
|
|
705
|
+
"health_check",
|
|
706
|
+
"diagnostics",
|
|
707
|
+
"getDiagnostics",
|
|
708
|
+
"systemInfo",
|
|
709
|
+
"system_info",
|
|
710
|
+
"info",
|
|
711
|
+
"getInfo",
|
|
712
|
+
"health",
|
|
713
|
+
"getHealth",
|
|
714
|
+
"status",
|
|
715
|
+
"getStatus",
|
|
716
|
+
"adapters",
|
|
717
|
+
"listAdapters",
|
|
718
|
+
"list_adapters",
|
|
719
|
+
"getAdapters",
|
|
720
|
+
"get_adapters"
|
|
721
|
+
];
|
|
722
|
+
const systemObj = {
|
|
723
|
+
ping: () => wrapPromise(Promise.resolve(wrapResult({ success: true, status: "pong" })), "ping"),
|
|
724
|
+
version: () => wrapPromise(Promise.resolve(wrapResult({ success: true, version: VERSION, name: "memory-journal-mcp" })), "version")
|
|
725
|
+
};
|
|
726
|
+
for (const k of statsKeys) systemObj[k] = getStats;
|
|
727
|
+
Object.assign(systemCallable, systemObj);
|
|
728
|
+
return new Proxy(systemCallable, {
|
|
729
|
+
apply: (_t, _thisArg, args) => getStats(...args),
|
|
730
|
+
get(t, p) {
|
|
731
|
+
if (typeof p === "symbol" || p === "then") return void 0;
|
|
732
|
+
if (p in t) return Reflect.get(t, p);
|
|
733
|
+
return getStats;
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function createContextNamespaceProxy(contextObj) {
|
|
738
|
+
const projNum = contextObj?.["project_number"] ?? contextObj?.["projectNumber"] ?? 1;
|
|
739
|
+
const sessId = contextObj?.["session_id"] ?? contextObj?.["sessionId"] ?? "session-default";
|
|
740
|
+
const wsId = contextObj?.["workspace_id"] ?? contextObj?.["workspaceId"] ?? "default";
|
|
741
|
+
const projId = contextObj?.["project_id"] ?? contextObj?.["projectId"] ?? projNum;
|
|
742
|
+
const contextData = {
|
|
743
|
+
success: true,
|
|
744
|
+
project_number: projNum,
|
|
745
|
+
projectNumber: projNum,
|
|
746
|
+
session_id: sessId,
|
|
747
|
+
sessionId: sessId,
|
|
748
|
+
workspace_id: wsId,
|
|
749
|
+
workspaceId: wsId,
|
|
750
|
+
project_id: projId,
|
|
751
|
+
projectId: projId,
|
|
752
|
+
...contextObj ?? {}
|
|
753
|
+
};
|
|
754
|
+
const getContextRpc = (keyOrObj) => {
|
|
755
|
+
if (typeof keyOrObj === "string" && keyOrObj in contextData) {
|
|
756
|
+
return wrapPromise(Promise.resolve(wrapResult(contextData[keyOrObj])), "get_context");
|
|
757
|
+
}
|
|
758
|
+
return wrapPromise(Promise.resolve(wrapResult(contextData)), "get_context");
|
|
759
|
+
};
|
|
760
|
+
const contextCallable = (...args) => getContextRpc(args[0]);
|
|
761
|
+
Object.assign(contextCallable, {
|
|
762
|
+
get: getContextRpc,
|
|
763
|
+
getContext: getContextRpc,
|
|
764
|
+
get_context: getContextRpc,
|
|
765
|
+
find: getContextRpc,
|
|
766
|
+
list: getContextRpc,
|
|
767
|
+
...contextData
|
|
768
|
+
});
|
|
769
|
+
const contextProxy = new Proxy(contextCallable, {
|
|
770
|
+
apply: (_t, _thisArg, args) => getContextRpc(args[0]),
|
|
771
|
+
get(t, p) {
|
|
772
|
+
if (typeof p === "symbol" || p === "then") return void 0;
|
|
773
|
+
if (p in t) return Reflect.get(t, p);
|
|
774
|
+
if (typeof p === "string") {
|
|
775
|
+
if (["get", "getContext", "get_context", "find", "list"].includes(p)) return getContextRpc;
|
|
776
|
+
if (p in contextData) return contextData[p];
|
|
777
|
+
}
|
|
778
|
+
return Reflect.get(t, p);
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
return { contextProxy, getContextRpc };
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// src/codemode/worker-api-proxy.ts
|
|
785
|
+
var FACTORY_METHOD_NAMES = /* @__PURE__ */ new Set([
|
|
786
|
+
"getInstance",
|
|
787
|
+
"get_instance",
|
|
788
|
+
"createInstance",
|
|
789
|
+
"create_instance",
|
|
790
|
+
"getClient",
|
|
791
|
+
"get_client",
|
|
792
|
+
"createClient",
|
|
793
|
+
"create_client",
|
|
794
|
+
"initClient",
|
|
795
|
+
"init_client",
|
|
796
|
+
"initInstance",
|
|
797
|
+
"init_instance",
|
|
798
|
+
"getJournal",
|
|
799
|
+
"get_journal",
|
|
800
|
+
"loadJournal",
|
|
801
|
+
"load_journal",
|
|
802
|
+
"loadMemory",
|
|
803
|
+
"load_memory",
|
|
804
|
+
"getDatabase",
|
|
805
|
+
"get_database",
|
|
806
|
+
"getDb",
|
|
807
|
+
"get_db",
|
|
808
|
+
"connectToDatabase",
|
|
809
|
+
"connect_to_database",
|
|
810
|
+
"openDatabase",
|
|
811
|
+
"open_database",
|
|
812
|
+
"init",
|
|
813
|
+
"initialize",
|
|
814
|
+
"connect",
|
|
815
|
+
"open",
|
|
816
|
+
"default"
|
|
817
|
+
]);
|
|
818
|
+
var KNOWN_PROMPTS = [
|
|
819
|
+
"session-summary",
|
|
820
|
+
"plan-draft",
|
|
821
|
+
"adversarial-review",
|
|
822
|
+
"copilot-validation",
|
|
823
|
+
"plan-refinement",
|
|
824
|
+
"team-session-summary"
|
|
825
|
+
];
|
|
826
|
+
function getPropOrSnake(obj, snake, camel) {
|
|
827
|
+
if (typeof obj === "object" && obj !== null || typeof obj === "function") {
|
|
828
|
+
return Reflect.get(obj, snake) ?? Reflect.get(obj, camel);
|
|
829
|
+
}
|
|
830
|
+
return void 0;
|
|
67
831
|
}
|
|
68
|
-
function buildApiProxy(methods, schemas, readonlyMode) {
|
|
832
|
+
function buildApiProxy(rpcCall2, methods, schemas, readonlyMode, contextObj) {
|
|
69
833
|
const api = {};
|
|
834
|
+
const safeRpcCall = (group, method, args) => rpcCall2(group, method, args).catch((err) => ({
|
|
835
|
+
success: false,
|
|
836
|
+
error: err instanceof Error ? err.message : String(err),
|
|
837
|
+
code: "EXECUTION_ERROR",
|
|
838
|
+
category: "execution",
|
|
839
|
+
recoverable: true
|
|
840
|
+
}));
|
|
841
|
+
const invokeRpc = (g, m, args) => {
|
|
842
|
+
const intercept = applyArgInterceptions(m, args);
|
|
843
|
+
if ("error" in intercept) {
|
|
844
|
+
return wrapPromise(Promise.resolve(wrapResult(intercept.error)), m);
|
|
845
|
+
}
|
|
846
|
+
return wrapPromise(safeRpcCall(g, m, intercept.args).then(wrapResult), m);
|
|
847
|
+
};
|
|
848
|
+
const createMethodProxyFn = (groupName, methodName, schemaFallbackKey) => {
|
|
849
|
+
const fn = (...args) => invokeRpc(groupName, methodName, args);
|
|
850
|
+
attachMethodIntrospection(
|
|
851
|
+
fn,
|
|
852
|
+
groupName,
|
|
853
|
+
methodName,
|
|
854
|
+
() => schemas?.[groupName]?.[methodName] ?? (schemaFallbackKey !== void 0 ? schemas?.[groupName]?.[schemaFallbackKey] : void 0) ?? "unknown"
|
|
855
|
+
);
|
|
856
|
+
return fn;
|
|
857
|
+
};
|
|
70
858
|
for (const [group, methodNames] of Object.entries(methods)) {
|
|
859
|
+
if (!Array.isArray(methodNames)) continue;
|
|
71
860
|
if (group === "_topLevel") {
|
|
72
861
|
for (const methodName of methodNames) {
|
|
73
|
-
|
|
74
|
-
const result = await rpcCall("_topLevel", methodName, args);
|
|
75
|
-
return wrapResult(result);
|
|
76
|
-
};
|
|
77
|
-
Object.assign(proxyFn, {
|
|
78
|
-
schema: () => Promise.resolve(schemas?.["_topLevel"]?.[methodName] ?? "any")
|
|
79
|
-
});
|
|
80
|
-
api[methodName] = proxyFn;
|
|
862
|
+
api[methodName] = createMethodProxyFn("_topLevel", methodName);
|
|
81
863
|
}
|
|
82
864
|
continue;
|
|
83
865
|
}
|
|
84
866
|
const groupProxy = {};
|
|
85
867
|
for (const methodName of methodNames) {
|
|
86
|
-
|
|
87
|
-
const result = await rpcCall(group, methodName, args);
|
|
88
|
-
return wrapResult(result);
|
|
89
|
-
};
|
|
90
|
-
Object.assign(proxyFn, {
|
|
91
|
-
schema: () => Promise.resolve(schemas?.[group]?.[methodName] ?? "any")
|
|
92
|
-
});
|
|
93
|
-
groupProxy[methodName] = proxyFn;
|
|
868
|
+
groupProxy[methodName] = createMethodProxyFn(group, methodName);
|
|
94
869
|
}
|
|
95
|
-
groupProxy["help"] = () => Promise.resolve({
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
870
|
+
groupProxy["help"] = () => Promise.resolve({ group, methods: methodNames });
|
|
871
|
+
groupProxy["describe"] = groupProxy["help"];
|
|
872
|
+
const groupCallable = function() {
|
|
873
|
+
};
|
|
874
|
+
Object.assign(groupCallable, groupProxy);
|
|
875
|
+
api[group] = new Proxy(groupCallable, {
|
|
876
|
+
apply(_target, _thisArg, args) {
|
|
877
|
+
const primaryMethod = methodNames.find((m) => !m.endsWith("_help") && m !== "help");
|
|
878
|
+
const fn = primaryMethod !== void 0 ? groupProxy[primaryMethod] : void 0;
|
|
879
|
+
if (fn !== void 0) return fn(...args);
|
|
880
|
+
return wrapPromise(
|
|
881
|
+
Promise.resolve(
|
|
882
|
+
wrapResult({
|
|
883
|
+
success: false,
|
|
884
|
+
error: `Group '${group}' is a tool namespace, not a function. Available methods in '${group}': ${methodNames.join(", ")}.`,
|
|
885
|
+
code: "VALIDATION_ERROR",
|
|
886
|
+
category: "validation",
|
|
887
|
+
recoverable: true
|
|
888
|
+
})
|
|
889
|
+
),
|
|
890
|
+
group
|
|
891
|
+
);
|
|
892
|
+
},
|
|
100
893
|
get(target, prop) {
|
|
101
894
|
if (typeof prop === "symbol") return void 0;
|
|
102
895
|
const key = prop;
|
|
103
|
-
if (key in target) return target
|
|
104
|
-
if (key
|
|
896
|
+
if (key in target) return Reflect.get(target, key);
|
|
897
|
+
if (/[A-Z]/.test(key)) {
|
|
898
|
+
const snakeKey = key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
899
|
+
if (snakeKey in target) return Reflect.get(target, snakeKey);
|
|
900
|
+
}
|
|
901
|
+
const aliases = METHOD_ALIASES[group];
|
|
902
|
+
let resolvedKey = key;
|
|
903
|
+
if (aliases?.[key] !== void 0) {
|
|
904
|
+
const canonicalCamel = aliases[key];
|
|
905
|
+
const canonicalSnake = canonicalCamel.replace(/[A-Z]/g, (l) => `_${l.toLowerCase()}`);
|
|
906
|
+
if (canonicalSnake in target) return Reflect.get(target, canonicalSnake);
|
|
907
|
+
if (canonicalCamel in target) return Reflect.get(target, canonicalCamel);
|
|
908
|
+
resolvedKey = canonicalCamel;
|
|
909
|
+
}
|
|
910
|
+
if (group === "core") {
|
|
911
|
+
if (resolvedKey === "projects" || resolvedKey === "project" || key === "projects" || key === "project") {
|
|
912
|
+
return api["projects"];
|
|
913
|
+
}
|
|
914
|
+
if (resolvedKey === "semanticSearch" || key === "semantic_search") {
|
|
915
|
+
return getPropOrSnake(api["semantic"], "semantic_search", "semanticSearch");
|
|
916
|
+
}
|
|
917
|
+
if (resolvedKey === "vectorStats" || key === "vector_stats") {
|
|
918
|
+
return getPropOrSnake(api["semantic"], "vector_stats", "vectorStats");
|
|
919
|
+
}
|
|
920
|
+
if (resolvedKey === "searchAuditLog" || key === "search_audit_log") {
|
|
921
|
+
return getPropOrSnake(api["admin"], "search_audit_log", "searchAuditLog");
|
|
922
|
+
}
|
|
923
|
+
if (resolvedKey === "listDeletedEntries" || key === "list_deleted_entries") {
|
|
924
|
+
return getPropOrSnake(api["admin"], "list_deleted_entries", "listDeletedEntries");
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
if (resolvedKey === "getConfig") return createGetConfigInterceptor();
|
|
928
|
+
if (resolvedKey === "getBriefing") return createGetBriefingInterceptor();
|
|
929
|
+
if (resolvedKey === "readResource") return createReadResourceInterceptor();
|
|
930
|
+
if (resolvedKey === "then") return void 0;
|
|
931
|
+
if (typeof resolvedKey === "string") {
|
|
932
|
+
const snakeKey = /[A-Z]/.test(resolvedKey) ? resolvedKey.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`) : resolvedKey;
|
|
933
|
+
const teamSnakeKey = `team_${snakeKey}`;
|
|
934
|
+
const teamGroup = Object.keys(methods).find((g) => methods[g]?.includes(teamSnakeKey));
|
|
935
|
+
if (teamGroup !== void 0 && !Object.keys(methods).some((g) => methods[g]?.includes(snakeKey))) {
|
|
936
|
+
return createMethodProxyFn(teamGroup, teamSnakeKey);
|
|
937
|
+
}
|
|
938
|
+
const foundGroup = Object.keys(methods).find((g) => methods[g]?.includes(snakeKey));
|
|
939
|
+
if (foundGroup !== void 0) {
|
|
940
|
+
return createMethodProxyFn(foundGroup, snakeKey, resolvedKey);
|
|
941
|
+
}
|
|
942
|
+
}
|
|
105
943
|
const available = methodNames.join(", ") || "none";
|
|
106
|
-
const reason = readonlyMode ?
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
944
|
+
const reason = readonlyMode === true ? `\u{1F6E0}\uFE0F AUTONOMOUS HEALING: Operation '${key}' is blocked in readonly mode. Read operations only.` : methodNames.length === 0 ? `\u{1F6E0}\uFE0F AUTONOMOUS HEALING: Operation '${key}' is not available \u2014 this group has no methods (read-only mode?). Available: ${available}.` : `\u{1F6E0}\uFE0F AUTONOMOUS HEALING: Operation '${key}' is not found in group '${group}'. Available: ${available}.`;
|
|
945
|
+
const fallbackFn = (..._args) => wrapPromise(
|
|
946
|
+
Promise.resolve(
|
|
947
|
+
wrapResult({
|
|
948
|
+
success: false,
|
|
949
|
+
error: reason,
|
|
950
|
+
code: "VALIDATION_ERROR",
|
|
951
|
+
category: "validation",
|
|
952
|
+
recoverable: true
|
|
953
|
+
})
|
|
954
|
+
),
|
|
955
|
+
key
|
|
956
|
+
);
|
|
957
|
+
attachMethodIntrospection(fallbackFn, group, key, () => "unknown", reason);
|
|
958
|
+
return fallbackFn;
|
|
959
|
+
},
|
|
960
|
+
set: () => false,
|
|
961
|
+
defineProperty: () => false,
|
|
962
|
+
deleteProperty: () => false,
|
|
963
|
+
setPrototypeOf: () => false
|
|
111
964
|
});
|
|
112
|
-
api[group] = groupProxyWrapped;
|
|
113
965
|
}
|
|
966
|
+
api["schema"] = createSchemaProxy(safeRpcCall);
|
|
114
967
|
api["help"] = () => {
|
|
115
|
-
const groups = Object.keys(methods).filter(
|
|
116
|
-
(g) => g !== "_topLevel" && g !== "memory" && g !== "entries"
|
|
117
|
-
);
|
|
968
|
+
const groups = Object.keys(methods).filter((g) => g !== "_topLevel" && g !== "memory" && g !== "entries");
|
|
118
969
|
let totalMethods = 0;
|
|
119
|
-
for (const group of groups)
|
|
120
|
-
totalMethods += methods[group]?.length ?? 0;
|
|
121
|
-
}
|
|
970
|
+
for (const group of groups) totalMethods += methods[group]?.length ?? 0;
|
|
122
971
|
return Promise.resolve({
|
|
123
972
|
groups,
|
|
124
973
|
totalMethods,
|
|
125
974
|
usage: "Use mj.<group>.help() for group details. Use mj.<group>.<method>.schema() for parameter details."
|
|
126
975
|
});
|
|
127
976
|
};
|
|
977
|
+
api["describe"] = api["help"];
|
|
978
|
+
const projectsProxy = createProjectsProxy(methods, invokeRpc);
|
|
979
|
+
api["projects"] = projectsProxy;
|
|
980
|
+
api["project"] = projectsProxy;
|
|
981
|
+
const tagsProxy = createTagsProxy(methods, invokeRpc);
|
|
982
|
+
api["tags"] = tagsProxy;
|
|
983
|
+
api["tag"] = tagsProxy;
|
|
984
|
+
const systemProxy = createSystemProxy(methods, invokeRpc);
|
|
985
|
+
api["system"] = systemProxy;
|
|
986
|
+
api["adapters"] = systemProxy;
|
|
987
|
+
const { contextProxy, getContextRpc } = createContextNamespaceProxy(contextObj);
|
|
988
|
+
api["context"] = contextProxy;
|
|
989
|
+
api["getContext"] = getContextRpc;
|
|
990
|
+
api["get_context"] = getContextRpc;
|
|
991
|
+
api["getDatabase"] = () => api;
|
|
992
|
+
api["get_database"] = () => api;
|
|
993
|
+
api["getDb"] = () => api;
|
|
994
|
+
api["get_db"] = () => api;
|
|
995
|
+
api["connectToDatabase"] = () => api;
|
|
996
|
+
api["openDatabase"] = () => api;
|
|
128
997
|
return new Proxy(api, {
|
|
129
998
|
get(target, prop) {
|
|
130
999
|
if (typeof prop === "symbol") return void 0;
|
|
131
1000
|
if (prop in target) return target[prop];
|
|
1001
|
+
if (prop === "gitApi") return target["git"];
|
|
1002
|
+
if (prop === "journal" || prop === "memory" || prop === "entries" || prop === "entry")
|
|
1003
|
+
return target["core"] ?? target;
|
|
1004
|
+
if (prop === "schema") return target["schema"];
|
|
1005
|
+
if (prop === "projects" || prop === "project") return target["projects"];
|
|
1006
|
+
if (prop === "tags" || prop === "tag") return target["tags"];
|
|
1007
|
+
if (prop === "system") return target["system"];
|
|
1008
|
+
if (prop === "context") return target["context"];
|
|
1009
|
+
if (prop === "getContext" || prop === "get_context") return target["getContext"];
|
|
1010
|
+
if (prop === "sqlite" || prop === "sqlite3" || prop === "db") return target;
|
|
132
1011
|
if (prop === "then") return void 0;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
()
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (typeof subProp === "symbol") return void 0;
|
|
144
|
-
if (subProp === "then") return void 0;
|
|
145
|
-
return (..._args) => {
|
|
146
|
-
throw new Error(
|
|
147
|
-
`${reason} (Attempted to access 'mj.${prop}.${subProp}')`
|
|
148
|
-
);
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
async function executeCode(code, methodList, schemaList, timeoutMs, contextObj, readonlyMode) {
|
|
157
|
-
const startCpu = process.cpuUsage();
|
|
158
|
-
const startTime = performance.now();
|
|
159
|
-
try {
|
|
160
|
-
const mjApi = buildApiProxy(methodList, schemaList, readonlyMode);
|
|
161
|
-
const shimMj = new Proxy(mjApi, {
|
|
162
|
-
get(target, prop) {
|
|
163
|
-
if (prop === "mj" || prop === "journal" || prop === "memory") return shimMj;
|
|
164
|
-
if (prop === "executeCode") {
|
|
165
|
-
if ("codemode" in target) {
|
|
166
|
-
const codemodeGroup = target["codemode"];
|
|
167
|
-
return codemodeGroup["mjExecuteCode"] ?? codemodeGroup["executeCode"];
|
|
1012
|
+
if (FACTORY_METHOD_NAMES.has(prop)) return createFactoryFnProxy(api);
|
|
1013
|
+
if (typeof prop === "string") {
|
|
1014
|
+
const snakeKey = /[A-Z]/.test(prop) ? prop.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`) : prop;
|
|
1015
|
+
for (const [g, groupAliases] of Object.entries(METHOD_ALIASES)) {
|
|
1016
|
+
if (groupAliases?.[prop] !== void 0) {
|
|
1017
|
+
const canonicalCamel = groupAliases[prop];
|
|
1018
|
+
const canonicalSnake = canonicalCamel.replace(/[A-Z]/g, (l) => `_${l.toLowerCase()}`);
|
|
1019
|
+
if (methods[g]?.includes(canonicalSnake)) {
|
|
1020
|
+
return createMethodProxyFn(g, canonicalSnake);
|
|
1021
|
+
}
|
|
168
1022
|
}
|
|
169
|
-
return () => Promise.reject(
|
|
170
|
-
new Error(
|
|
171
|
-
"You are already inside Code Mode execution. You do not need to call executeCode again. Just write your logic directly (e.g., return await mj.core.createEntry(...))."
|
|
172
|
-
)
|
|
173
|
-
);
|
|
174
1023
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
)
|
|
180
|
-
);
|
|
1024
|
+
const teamSnakeKey = `team_${snakeKey}`;
|
|
1025
|
+
const teamGroup = Object.keys(methods).find((g) => methods[g]?.includes(teamSnakeKey));
|
|
1026
|
+
if (teamGroup !== void 0 && !Object.keys(methods).some((g) => methods[g]?.includes(snakeKey))) {
|
|
1027
|
+
return createMethodProxyFn(teamGroup, teamSnakeKey);
|
|
181
1028
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return
|
|
185
|
-
}
|
|
186
|
-
if (prop === "append" && "core" in target) {
|
|
187
|
-
const coreGroup = target["core"];
|
|
188
|
-
const createEntry = coreGroup["createEntry"];
|
|
189
|
-
return (arg1, arg2, arg3) => {
|
|
190
|
-
const tags = Array.isArray(arg1) ? arg1 : [typeof arg1 === "string" ? arg1 : "test"];
|
|
191
|
-
const content = typeof arg2 === "string" ? arg2 : arg2 != null ? JSON.stringify(arg2) : "";
|
|
192
|
-
const metadata = typeof arg3 === "object" && arg3 !== null ? { ...arg3 } : void 0;
|
|
193
|
-
const typeVal = metadata?.["type"];
|
|
194
|
-
const type = typeof typeVal === "string" && typeVal !== "" ? typeVal : "test_entry";
|
|
195
|
-
if (metadata && "type" in metadata) delete metadata["type"];
|
|
196
|
-
return createEntry({ type, tags, content, metadata });
|
|
197
|
-
};
|
|
1029
|
+
const foundGroup = Object.keys(methods).find((g) => methods[g]?.includes(snakeKey));
|
|
1030
|
+
if (foundGroup !== void 0) {
|
|
1031
|
+
return createMethodProxyFn(foundGroup, snakeKey);
|
|
198
1032
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
batchInsert: ["core", "createEntry"],
|
|
210
|
-
readQuery: ["search", "searchEntries"]
|
|
211
|
-
};
|
|
212
|
-
const mapping = DB_TO_JOURNAL[prop];
|
|
213
|
-
if (mapping !== void 0) {
|
|
214
|
-
const [group, method] = mapping;
|
|
215
|
-
if (group in target) {
|
|
216
|
-
return target[group][method];
|
|
217
|
-
}
|
|
218
|
-
}
|
|
1033
|
+
}
|
|
1034
|
+
const available = Object.keys(methods).filter((k) => k !== "_topLevel").join(", ");
|
|
1035
|
+
let reason = `Group or property '${prop}' is not found on 'mj'. Available groups: ${available}. Use mj.help() for more info.`;
|
|
1036
|
+
if (typeof prop === "string") {
|
|
1037
|
+
const normalized = prop.replace(/^mj_/, "").replace(/_/g, "-");
|
|
1038
|
+
const isPrompt = KNOWN_PROMPTS.includes(normalized) || KNOWN_PROMPTS.includes(prop) || KNOWN_PROMPTS.includes(prop.replace(/^mj_/, ""));
|
|
1039
|
+
if (isPrompt) {
|
|
1040
|
+
reason = `'${prop}' is an MCP Prompt, not an MCP Tool. Code Mode cannot invoke MCP Prompts directly. Please use the 'get_prompt' tool (or your native MCP Prompts integration) outside of Code Mode to evaluate it, then use 'mj.core.createEntry' to save the result.`;
|
|
1041
|
+
} else if (prop.startsWith("mj_")) {
|
|
1042
|
+
reason = `'${prop}' is not a valid root tool in Code Mode. Code Mode uses namespaced groups (e.g., 'mj.core.searchEntries'). Use 'mj.help()' to see available namespaces.`;
|
|
219
1043
|
}
|
|
220
|
-
return Reflect.get(target, prop);
|
|
221
1044
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
require: void 0,
|
|
246
|
-
__dirname: void 0,
|
|
247
|
-
__filename: void 0,
|
|
248
|
-
global: void 0,
|
|
249
|
-
globalThis: void 0,
|
|
250
|
-
Proxy: void 0
|
|
251
|
-
};
|
|
252
|
-
for (const key of Object.keys(mjApi)) {
|
|
253
|
-
if (key in sandbox) continue;
|
|
254
|
-
const val = shimMj[key];
|
|
255
|
-
if (typeof val === "function") {
|
|
256
|
-
sandbox[key] = val;
|
|
1045
|
+
return createUnknownGroupRejectionProxy(prop, reason);
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
function hardenOuterFunctionPrototypes() {
|
|
1050
|
+
const noopConstructor = Object.freeze(function ForbiddenConstructor() {
|
|
1051
|
+
throw new Error("Dynamic code generation is disabled in sandbox");
|
|
1052
|
+
});
|
|
1053
|
+
const AsyncFnProto = Object.getPrototypeOf(async function() {
|
|
1054
|
+
});
|
|
1055
|
+
const GenFnProto = Object.getPrototypeOf(function* () {
|
|
1056
|
+
});
|
|
1057
|
+
const AsyncGenFnProto = Object.getPrototypeOf(async function* () {
|
|
1058
|
+
});
|
|
1059
|
+
for (const proto of [Object.prototype, Function.prototype, AsyncFnProto, GenFnProto, AsyncGenFnProto]) {
|
|
1060
|
+
if (proto !== null && proto !== void 0) {
|
|
1061
|
+
try {
|
|
1062
|
+
Object.defineProperty(proto, "constructor", {
|
|
1063
|
+
value: noopConstructor,
|
|
1064
|
+
writable: false,
|
|
1065
|
+
configurable: false
|
|
1066
|
+
});
|
|
1067
|
+
} catch {
|
|
257
1068
|
}
|
|
258
1069
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
1070
|
+
}
|
|
1071
|
+
const outerBuiltins = [
|
|
1072
|
+
Object,
|
|
1073
|
+
Function,
|
|
1074
|
+
Array,
|
|
1075
|
+
String,
|
|
1076
|
+
Number,
|
|
1077
|
+
Boolean,
|
|
1078
|
+
RegExp,
|
|
1079
|
+
Error,
|
|
1080
|
+
TypeError,
|
|
1081
|
+
RangeError,
|
|
1082
|
+
ReferenceError,
|
|
1083
|
+
SyntaxError,
|
|
1084
|
+
URIError,
|
|
1085
|
+
EvalError,
|
|
1086
|
+
Map,
|
|
1087
|
+
Set,
|
|
1088
|
+
WeakMap,
|
|
1089
|
+
WeakSet,
|
|
1090
|
+
Promise,
|
|
1091
|
+
Date,
|
|
1092
|
+
ArrayBuffer,
|
|
1093
|
+
DataView,
|
|
1094
|
+
JSON,
|
|
1095
|
+
Math
|
|
1096
|
+
];
|
|
1097
|
+
for (const B of outerBuiltins) {
|
|
1098
|
+
if (typeof B === "function" && B.prototype !== void 0 && B.prototype !== null) {
|
|
1099
|
+
try {
|
|
1100
|
+
Object.freeze(B.prototype);
|
|
1101
|
+
} catch {
|
|
264
1102
|
}
|
|
265
|
-
});
|
|
266
|
-
vm.runInContext(
|
|
267
|
-
`(function() {
|
|
268
|
-
"use strict";
|
|
269
|
-
const builtins = [
|
|
270
|
-
Object, Function, Array, String, Number, Boolean, RegExp,
|
|
271
|
-
Error, TypeError, RangeError, ReferenceError, SyntaxError,
|
|
272
|
-
URIError, EvalError, Map, Set, WeakMap, WeakSet,
|
|
273
|
-
Promise, Date, ArrayBuffer, DataView,
|
|
274
|
-
Int8Array, Uint8Array, Uint8ClampedArray,
|
|
275
|
-
Int16Array, Uint16Array, Int32Array, Uint32Array,
|
|
276
|
-
Float32Array, Float64Array, BigInt64Array, BigUint64Array,
|
|
277
|
-
JSON, Math,
|
|
278
|
-
];
|
|
279
|
-
for (const B of builtins) {
|
|
280
|
-
if (B && typeof B === "function" && B.prototype) {
|
|
281
|
-
try { Object.freeze(B.prototype); } catch(e) {}
|
|
282
|
-
}
|
|
283
|
-
try { Object.freeze(B); } catch(e) {}
|
|
284
|
-
}
|
|
285
|
-
try { Object.freeze(Object.prototype); } catch(e) {}
|
|
286
|
-
try { Object.freeze(Function.prototype); } catch(e) {}
|
|
287
|
-
})()`,
|
|
288
|
-
context
|
|
289
|
-
);
|
|
290
|
-
const wrappedCode = `(async () => { ${transformAutoReturn(code)} })()`;
|
|
291
|
-
const script = new vm.Script(wrappedCode, {
|
|
292
|
-
filename: "codemode-execution.js"
|
|
293
|
-
});
|
|
294
|
-
const resultPromise = script.runInContext(context, {
|
|
295
|
-
timeout: timeoutMs
|
|
296
|
-
});
|
|
297
|
-
const result = await resultPromise;
|
|
298
|
-
const endTime = performance.now();
|
|
299
|
-
const endCpu = process.cpuUsage(startCpu);
|
|
300
|
-
const metrics = {
|
|
301
|
-
wallTimeMs: Math.round(endTime - startTime),
|
|
302
|
-
cpuTimeMs: Math.round((endCpu.user + endCpu.system) / 1e3),
|
|
303
|
-
memoryUsedMb: 0
|
|
304
|
-
};
|
|
305
|
-
return { success: true, result, metrics };
|
|
306
|
-
} catch (err) {
|
|
307
|
-
const endTime = performance.now();
|
|
308
|
-
const endCpu = process.cpuUsage(startCpu);
|
|
309
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
310
|
-
if (error instanceof SyntaxError && error.message.includes("missing ) after argument list")) {
|
|
311
|
-
error.message += "\n\n\u{1F4A1} Tip: When passing long multi-line strings or markdown with embedded quotes, use template literals (backticks `) instead of single/double quotes to avoid escaping SyntaxErrors.";
|
|
312
1103
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
1104
|
+
try {
|
|
1105
|
+
Object.freeze(B);
|
|
1106
|
+
} catch {
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
for (const proto of [Object.prototype, Function.prototype, AsyncFnProto, GenFnProto, AsyncGenFnProto]) {
|
|
1110
|
+
if (proto !== null && proto !== void 0) {
|
|
1111
|
+
try {
|
|
1112
|
+
Object.freeze(proto);
|
|
1113
|
+
} catch {
|
|
321
1114
|
}
|
|
322
|
-
}
|
|
1115
|
+
}
|
|
323
1116
|
}
|
|
324
1117
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
pendingRpcRequests.clear();
|
|
343
|
-
rpcPort?.on("message", (response) => {
|
|
344
|
-
const pending = pendingRpcRequests.get(response.id);
|
|
345
|
-
if (pending) {
|
|
346
|
-
pendingRpcRequests.delete(response.id);
|
|
347
|
-
if (response.error) {
|
|
348
|
-
pending.reject(new Error(response.error));
|
|
349
|
-
} else {
|
|
350
|
-
pending.resolve(response.result);
|
|
351
|
-
}
|
|
1118
|
+
var FREEZE_INNER_CONTEXT_SCRIPT = new vm2.Script(`(function() {
|
|
1119
|
+
"use strict";
|
|
1120
|
+
const noopCtor = Object.freeze(function ForbiddenConstructor() {
|
|
1121
|
+
throw new Error("Dynamic code generation is disabled in sandbox");
|
|
1122
|
+
});
|
|
1123
|
+
const AsyncFnProto = Object.getPrototypeOf(async function() {});
|
|
1124
|
+
const GenFnProto = Object.getPrototypeOf(function*() {});
|
|
1125
|
+
const AsyncGenFnProto = Object.getPrototypeOf(async function*() {});
|
|
1126
|
+
for (const proto of [Function.prototype, AsyncFnProto, GenFnProto, AsyncGenFnProto]) {
|
|
1127
|
+
if (proto) {
|
|
1128
|
+
try {
|
|
1129
|
+
Object.defineProperty(proto, "constructor", {
|
|
1130
|
+
value: noopCtor,
|
|
1131
|
+
writable: false,
|
|
1132
|
+
configurable: false,
|
|
1133
|
+
});
|
|
1134
|
+
} catch(e) {}
|
|
352
1135
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const resultJson = JSON.stringify(
|
|
368
|
-
result.result,
|
|
369
|
-
(_key, value) => {
|
|
370
|
-
if (typeof value === "object" && value !== null) {
|
|
371
|
-
if (cache.has(value)) return "[Circular]";
|
|
372
|
-
cache.add(value);
|
|
373
|
-
}
|
|
374
|
-
if (typeof value === "string") {
|
|
375
|
-
bytes += Buffer.byteLength(value, "utf8") + 2;
|
|
376
|
-
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
377
|
-
bytes += Buffer.byteLength(String(value), "utf8");
|
|
378
|
-
} else {
|
|
379
|
-
bytes += 5;
|
|
380
|
-
}
|
|
381
|
-
if (bytes > egressLimit) {
|
|
382
|
-
throw new Error(`EgressLimitExceeded:${bytes}`);
|
|
383
|
-
}
|
|
384
|
-
return value;
|
|
385
|
-
}
|
|
386
|
-
);
|
|
387
|
-
if (resultJson !== void 0) {
|
|
388
|
-
const byteLength = Buffer.byteLength(resultJson, "utf8");
|
|
389
|
-
if (byteLength > egressLimit) {
|
|
390
|
-
throw new Error(`EgressLimitExceeded:${byteLength}`);
|
|
391
|
-
}
|
|
392
|
-
result.result = JSON.parse(resultJson);
|
|
393
|
-
} else {
|
|
394
|
-
result.result = void 0;
|
|
395
|
-
}
|
|
396
|
-
} catch (err) {
|
|
397
|
-
result.success = false;
|
|
398
|
-
const egressLimit = maxResultSize ?? 100 * 1024;
|
|
399
|
-
if (err instanceof Error && err.message.startsWith("EgressLimitExceeded:")) {
|
|
400
|
-
const actualBytesStr = err.message.split(":")[1];
|
|
401
|
-
const actualBytes = actualBytesStr !== void 0 ? Number(actualBytesStr) : egressLimit + 1;
|
|
402
|
-
const actualKb = (actualBytes / 1024).toFixed(1);
|
|
403
|
-
result.error = `Output limit exceeded: Result serialization exceeded the ${Math.round(egressLimit / 1024)}KB boundary (Actual size: >${actualKb}KB). Please aggregate or filter your results to reduce the payload size.`;
|
|
404
|
-
} else {
|
|
405
|
-
result.error = `Result could not be serialized or exceeded memory limits: ${err instanceof Error ? err.message : String(err)}`;
|
|
406
|
-
}
|
|
407
|
-
result.result = void 0;
|
|
1136
|
+
}
|
|
1137
|
+
const builtins = [
|
|
1138
|
+
Object, Function, Array, String, Number, Boolean, RegExp,
|
|
1139
|
+
Error, TypeError, RangeError, ReferenceError, SyntaxError,
|
|
1140
|
+
URIError, EvalError, Map, Set, WeakMap, WeakSet,
|
|
1141
|
+
Promise, Date, ArrayBuffer, DataView,
|
|
1142
|
+
Int8Array, Uint8Array, Uint8ClampedArray,
|
|
1143
|
+
Int16Array, Uint16Array, Int32Array, Uint32Array,
|
|
1144
|
+
Float32Array, Float64Array, BigInt64Array, BigUint64Array,
|
|
1145
|
+
JSON, Math,
|
|
1146
|
+
];
|
|
1147
|
+
for (const B of builtins) {
|
|
1148
|
+
if (B && typeof B === "function" && B.prototype) {
|
|
1149
|
+
try { Object.freeze(B.prototype); } catch(e) {}
|
|
408
1150
|
}
|
|
409
|
-
|
|
410
|
-
rpcPort?.close();
|
|
411
|
-
rpcPort = null;
|
|
412
|
-
parentPort?.postMessage({ type: "RESULT", id, result });
|
|
1151
|
+
try { Object.freeze(B); } catch(e) {}
|
|
413
1152
|
}
|
|
1153
|
+
for (const proto of [Object.prototype, Function.prototype, AsyncFnProto, GenFnProto, AsyncGenFnProto]) {
|
|
1154
|
+
if (proto) {
|
|
1155
|
+
try { Object.freeze(proto); } catch(e) {}
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
})()`);
|
|
1159
|
+
function freezeInnerVmContext(context) {
|
|
1160
|
+
FREEZE_INNER_CONTEXT_SCRIPT.runInContext(context);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
// src/codemode/worker/node-shims.ts
|
|
1164
|
+
var toStr = (val) => {
|
|
1165
|
+
if (typeof val === "string") return val;
|
|
1166
|
+
if (typeof val === "number" || typeof val === "boolean") return `${val}`;
|
|
1167
|
+
return "";
|
|
1168
|
+
};
|
|
1169
|
+
function createSafeFsShim(contextObj) {
|
|
1170
|
+
const readContent = () => contextObj !== void 0 && typeof contextObj["content"] === "string" ? contextObj["content"] : "";
|
|
1171
|
+
return {
|
|
1172
|
+
existsSync: (filePath) => {
|
|
1173
|
+
if (filePath === void 0 || filePath === null) return false;
|
|
1174
|
+
const p = toStr(filePath).toLowerCase();
|
|
1175
|
+
return p.includes(".db") || p.includes("memory") || p.includes("journal") || p.includes("sqlite") || p.length > 0;
|
|
1176
|
+
},
|
|
1177
|
+
statSync: (_filePath) => ({
|
|
1178
|
+
size: 1048576,
|
|
1179
|
+
isFile: () => true,
|
|
1180
|
+
isDirectory: () => false,
|
|
1181
|
+
mtime: /* @__PURE__ */ new Date(),
|
|
1182
|
+
birthtime: /* @__PURE__ */ new Date()
|
|
1183
|
+
}),
|
|
1184
|
+
stat: (_filePath, cb) => {
|
|
1185
|
+
const s = {
|
|
1186
|
+
size: 1048576,
|
|
1187
|
+
isFile: () => true,
|
|
1188
|
+
isDirectory: () => false,
|
|
1189
|
+
mtime: /* @__PURE__ */ new Date(),
|
|
1190
|
+
birthtime: /* @__PURE__ */ new Date()
|
|
1191
|
+
};
|
|
1192
|
+
if (typeof cb === "function") cb(null, s);
|
|
1193
|
+
return Promise.resolve(s);
|
|
1194
|
+
},
|
|
1195
|
+
lstatSync: (_filePath) => ({
|
|
1196
|
+
size: 1048576,
|
|
1197
|
+
isFile: () => true,
|
|
1198
|
+
isDirectory: () => false,
|
|
1199
|
+
mtime: /* @__PURE__ */ new Date(),
|
|
1200
|
+
birthtime: /* @__PURE__ */ new Date()
|
|
1201
|
+
}),
|
|
1202
|
+
readFileSync: (_filePath) => readContent(),
|
|
1203
|
+
readFile: (_filePath, cb) => {
|
|
1204
|
+
const data = readContent();
|
|
1205
|
+
if (typeof cb === "function") cb(null, data);
|
|
1206
|
+
return Promise.resolve(data);
|
|
1207
|
+
},
|
|
1208
|
+
writeFileSync: () => void 0,
|
|
1209
|
+
writeFile: () => Promise.resolve(void 0),
|
|
1210
|
+
mkdirSync: () => void 0,
|
|
1211
|
+
unlinkSync: () => void 0,
|
|
1212
|
+
readdirSync: () => [],
|
|
1213
|
+
promises: {
|
|
1214
|
+
stat: () => Promise.resolve({
|
|
1215
|
+
size: 1048576,
|
|
1216
|
+
isFile: () => true,
|
|
1217
|
+
isDirectory: () => false,
|
|
1218
|
+
mtime: /* @__PURE__ */ new Date(),
|
|
1219
|
+
birthtime: /* @__PURE__ */ new Date()
|
|
1220
|
+
}),
|
|
1221
|
+
readFile: () => Promise.resolve(readContent()),
|
|
1222
|
+
writeFile: () => Promise.resolve(void 0)
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
var pathShim = {
|
|
1227
|
+
join: (...parts) => parts.filter((p) => typeof p === "string" && p.length > 0).join("/").replace(/\/+/g, "/"),
|
|
1228
|
+
resolve: (...parts) => parts.filter((p) => typeof p === "string" && p.length > 0).join("/").replace(/\/+/g, "/"),
|
|
1229
|
+
basename: (p, ext) => {
|
|
1230
|
+
const b = toStr(p).split(/[/\\]/).pop() ?? "";
|
|
1231
|
+
return ext !== void 0 && b.endsWith(ext) ? b.slice(0, -ext.length) : b;
|
|
1232
|
+
},
|
|
1233
|
+
dirname: (p) => {
|
|
1234
|
+
const parts = toStr(p).split(/[/\\]/);
|
|
1235
|
+
parts.pop();
|
|
1236
|
+
return parts.join("/") || ".";
|
|
1237
|
+
},
|
|
1238
|
+
extname: (p) => {
|
|
1239
|
+
const b = toStr(p).split(/[/\\]/).pop() ?? "";
|
|
1240
|
+
const dot = b.lastIndexOf(".");
|
|
1241
|
+
return dot > 0 ? b.slice(dot) : "";
|
|
1242
|
+
},
|
|
1243
|
+
normalize: (p) => toStr(p).replace(/\\/g, "/"),
|
|
1244
|
+
isAbsolute: (p) => /^[a-zA-Z]:[/\\]|^\//.test(toStr(p)),
|
|
1245
|
+
sep: "/",
|
|
1246
|
+
delimiter: ":"
|
|
1247
|
+
};
|
|
1248
|
+
var consoleShim = Object.freeze({
|
|
1249
|
+
log: (...args) => args,
|
|
1250
|
+
warn: (...args) => args,
|
|
1251
|
+
error: (...args) => args,
|
|
1252
|
+
info: (...args) => args,
|
|
1253
|
+
debug: (...args) => args
|
|
1254
|
+
});
|
|
1255
|
+
function isPlainRecord(val) {
|
|
1256
|
+
return typeof val === "object" && val !== null && !Array.isArray(val);
|
|
1257
|
+
}
|
|
1258
|
+
function invokeGroupMethod(shimMj, group, camelName, snakeName, params) {
|
|
1259
|
+
const groupObj = shimMj[group];
|
|
1260
|
+
if (typeof groupObj === "object" && groupObj !== null || typeof groupObj === "function") {
|
|
1261
|
+
const fn = Reflect.get(groupObj, camelName) ?? Reflect.get(groupObj, snakeName);
|
|
1262
|
+
if (typeof fn === "function") {
|
|
1263
|
+
return fn(params);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return void 0;
|
|
1267
|
+
}
|
|
1268
|
+
function createPreparedStatementShim(sql, shimMj) {
|
|
1269
|
+
const parseSqlParams = (args) => {
|
|
1270
|
+
const cleanSql = sql.trim().replace(/^--[^\n]*\n/gm, "").trim();
|
|
1271
|
+
const isUpdate = /^UPDATE\b/i.test(cleanSql);
|
|
1272
|
+
const isInsert = /^INSERT\b/i.test(cleanSql);
|
|
1273
|
+
const isDelete = /^DELETE\b/i.test(cleanSql);
|
|
1274
|
+
const isSelect = /^SELECT\b/i.test(cleanSql);
|
|
1275
|
+
if (isUpdate) {
|
|
1276
|
+
const idMatch = /\bWHERE\s+[`"']?(?:id|entry_id)[`"']?\s*=\s*(?:\?|(\d+))/i.exec(
|
|
1277
|
+
cleanSql
|
|
1278
|
+
);
|
|
1279
|
+
let entryId;
|
|
1280
|
+
if (idMatch?.[1] !== void 0) {
|
|
1281
|
+
entryId = parseInt(idMatch[1], 10);
|
|
1282
|
+
}
|
|
1283
|
+
let content;
|
|
1284
|
+
let tags;
|
|
1285
|
+
let title;
|
|
1286
|
+
for (const arg of args) {
|
|
1287
|
+
if (typeof arg === "number" && entryId === void 0) {
|
|
1288
|
+
entryId = arg;
|
|
1289
|
+
} else if (typeof arg === "string") {
|
|
1290
|
+
if (arg.trim().startsWith("[") && arg.trim().endsWith("]")) {
|
|
1291
|
+
try {
|
|
1292
|
+
const parsed = JSON.parse(arg);
|
|
1293
|
+
if (Array.isArray(parsed)) {
|
|
1294
|
+
tags = parsed.map(String);
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
} catch {
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
if (content === void 0) {
|
|
1301
|
+
content = arg;
|
|
1302
|
+
} else {
|
|
1303
|
+
title ??= arg;
|
|
1304
|
+
}
|
|
1305
|
+
} else if (Array.isArray(arg)) {
|
|
1306
|
+
tags = arg.map(String);
|
|
1307
|
+
} else if (isPlainRecord(arg)) {
|
|
1308
|
+
if (typeof arg["entry_id"] === "number") entryId = arg["entry_id"];
|
|
1309
|
+
if (typeof arg["id"] === "number") entryId = arg["id"];
|
|
1310
|
+
if (typeof arg["content"] === "string") content = arg["content"];
|
|
1311
|
+
if (Array.isArray(arg["tags"])) tags = arg["tags"].map(String);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
if (content === void 0) {
|
|
1315
|
+
const setContentMatch = /\bSET\s+[\s\S]*?\bcontent\s*=\s*['"]([\s\S]*?)['"]/i.exec(cleanSql);
|
|
1316
|
+
if (setContentMatch?.[1] !== void 0) {
|
|
1317
|
+
content = setContentMatch[1];
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
const updatePayload = {};
|
|
1321
|
+
if (entryId !== void 0) updatePayload["entry_id"] = entryId;
|
|
1322
|
+
if (content !== void 0) updatePayload["content"] = content;
|
|
1323
|
+
if (tags !== void 0) updatePayload["tags"] = tags;
|
|
1324
|
+
if (title !== void 0) updatePayload["title"] = title;
|
|
1325
|
+
return { action: "update", params: updatePayload };
|
|
1326
|
+
}
|
|
1327
|
+
if (isInsert) {
|
|
1328
|
+
let content = "";
|
|
1329
|
+
let title = "Journal Entry";
|
|
1330
|
+
let tags = [];
|
|
1331
|
+
let entryType = "technical_decision";
|
|
1332
|
+
for (const arg of args) {
|
|
1333
|
+
if (typeof arg === "string") {
|
|
1334
|
+
if (arg.trim().startsWith("[") && arg.trim().endsWith("]")) {
|
|
1335
|
+
try {
|
|
1336
|
+
const parsed = JSON.parse(arg);
|
|
1337
|
+
if (Array.isArray(parsed)) {
|
|
1338
|
+
tags = parsed.map(String);
|
|
1339
|
+
continue;
|
|
1340
|
+
}
|
|
1341
|
+
} catch {
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
if (content === "") {
|
|
1345
|
+
content = arg;
|
|
1346
|
+
} else if (title === "Journal Entry") {
|
|
1347
|
+
title = arg;
|
|
1348
|
+
}
|
|
1349
|
+
} else if (Array.isArray(arg)) {
|
|
1350
|
+
tags = arg.map(String);
|
|
1351
|
+
} else if (isPlainRecord(arg)) {
|
|
1352
|
+
if (typeof arg["content"] === "string") content = arg["content"];
|
|
1353
|
+
if (typeof arg["title"] === "string") title = arg["title"];
|
|
1354
|
+
if (Array.isArray(arg["tags"])) tags = arg["tags"].map(String);
|
|
1355
|
+
if (typeof arg["entry_type"] === "string") entryType = arg["entry_type"];
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
return { action: "create", params: { content, title, tags, entry_type: entryType } };
|
|
1359
|
+
}
|
|
1360
|
+
if (isDelete) {
|
|
1361
|
+
let entryId;
|
|
1362
|
+
const idMatch = /\bWHERE\s+[`"']?(?:id|entry_id)[`"']?\s*=\s*(?:\?|(\d+))/i.exec(
|
|
1363
|
+
cleanSql
|
|
1364
|
+
);
|
|
1365
|
+
if (idMatch?.[1] !== void 0) entryId = parseInt(idMatch[1], 10);
|
|
1366
|
+
for (const arg of args) {
|
|
1367
|
+
if (typeof arg === "number") entryId = arg;
|
|
1368
|
+
}
|
|
1369
|
+
return { action: "delete", params: { entry_id: entryId ?? 0 } };
|
|
1370
|
+
}
|
|
1371
|
+
if (isSelect) {
|
|
1372
|
+
let entryId;
|
|
1373
|
+
const idMatch = /\bWHERE\s+[`"']?(?:id|entry_id)[`"']?\s*=\s*(?:\?|(\d+))/i.exec(
|
|
1374
|
+
cleanSql
|
|
1375
|
+
);
|
|
1376
|
+
if (idMatch?.[1] !== void 0) entryId = parseInt(idMatch[1], 10);
|
|
1377
|
+
for (const arg of args) {
|
|
1378
|
+
if (typeof arg === "number") entryId = arg;
|
|
1379
|
+
}
|
|
1380
|
+
if (entryId !== void 0) {
|
|
1381
|
+
return { action: "get_by_id", params: { entry_id: entryId } };
|
|
1382
|
+
}
|
|
1383
|
+
return { action: "list", params: { limit: 50 } };
|
|
1384
|
+
}
|
|
1385
|
+
return { action: "other", params: {} };
|
|
1386
|
+
};
|
|
1387
|
+
const executeOperation = (args) => {
|
|
1388
|
+
const { action, params } = parseSqlParams(args);
|
|
1389
|
+
if (action === "update") {
|
|
1390
|
+
return invokeGroupMethod(shimMj, "admin", "updateEntry", "update_entry", params) ?? invokeGroupMethod(shimMj, "core", "updateEntry", "update_entry", params) ?? Promise.resolve({ success: true, changes: 1 });
|
|
1391
|
+
}
|
|
1392
|
+
if (action === "create") {
|
|
1393
|
+
return invokeGroupMethod(shimMj, "core", "createEntry", "create_entry", params) ?? Promise.resolve({ success: true, changes: 1 });
|
|
1394
|
+
}
|
|
1395
|
+
if (action === "delete") {
|
|
1396
|
+
return invokeGroupMethod(shimMj, "admin", "deleteEntry", "delete_entry", params) ?? invokeGroupMethod(shimMj, "core", "deleteEntry", "delete_entry", params) ?? Promise.resolve({ success: true, changes: 1 });
|
|
1397
|
+
}
|
|
1398
|
+
if (action === "get_by_id") {
|
|
1399
|
+
return invokeGroupMethod(shimMj, "core", "getEntryById", "get_entry_by_id", params) ?? Promise.resolve({ success: true, changes: 1 });
|
|
1400
|
+
}
|
|
1401
|
+
if (action === "list") {
|
|
1402
|
+
return invokeGroupMethod(
|
|
1403
|
+
shimMj,
|
|
1404
|
+
"core",
|
|
1405
|
+
"getRecentEntries",
|
|
1406
|
+
"get_recent_entries",
|
|
1407
|
+
params
|
|
1408
|
+
) ?? Promise.resolve({ success: true, changes: 1 });
|
|
1409
|
+
}
|
|
1410
|
+
return Promise.resolve({ success: true, changes: 1 });
|
|
1411
|
+
};
|
|
1412
|
+
const stmtObj = {
|
|
1413
|
+
run: (...args) => {
|
|
1414
|
+
const res = executeOperation(args);
|
|
1415
|
+
return {
|
|
1416
|
+
changes: 1,
|
|
1417
|
+
lastInsertRowid: typeof args[2] === "number" ? args[2] : typeof args[0] === "number" ? args[0] : 1,
|
|
1418
|
+
success: true,
|
|
1419
|
+
then: (resolve) => Promise.resolve(res).then(resolve)
|
|
1420
|
+
};
|
|
1421
|
+
},
|
|
1422
|
+
get: (...args) => executeOperation(args),
|
|
1423
|
+
all: (...args) => executeOperation(args),
|
|
1424
|
+
iterate: (...args) => executeOperation(args),
|
|
1425
|
+
bind: () => stmtObj,
|
|
1426
|
+
columns: () => [],
|
|
1427
|
+
raw: () => stmtObj,
|
|
1428
|
+
pluck: () => stmtObj,
|
|
1429
|
+
expand: () => stmtObj,
|
|
1430
|
+
safeIntegers: () => stmtObj
|
|
1431
|
+
};
|
|
1432
|
+
return stmtObj;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// src/codemode/worker/namespace-shims.ts
|
|
1436
|
+
var DB_TO_JOURNAL = {
|
|
1437
|
+
listTables: ["analytics", "getStatistics"],
|
|
1438
|
+
describeTable: ["analytics", "getStatistics"],
|
|
1439
|
+
count: ["analytics", "getStatistics"],
|
|
1440
|
+
analyze: ["analytics", "getStatistics"],
|
|
1441
|
+
vacuum: ["analytics", "getStatistics"],
|
|
1442
|
+
integrityCheck: ["analytics", "getStatistics"],
|
|
1443
|
+
exists: ["core", "getEntryById"],
|
|
1444
|
+
upsert: ["core", "createEntry"],
|
|
1445
|
+
batchInsert: ["core", "createEntry"],
|
|
1446
|
+
readQuery: ["core", "readQuery"]
|
|
1447
|
+
};
|
|
1448
|
+
function createCallableShim(shimMj, fnName = "MemoryJournal") {
|
|
1449
|
+
const callableFn = function(..._args) {
|
|
1450
|
+
return shimMj;
|
|
1451
|
+
};
|
|
1452
|
+
return new Proxy(callableFn, {
|
|
1453
|
+
apply(_t, _thisArg, _args) {
|
|
1454
|
+
return shimMj;
|
|
1455
|
+
},
|
|
1456
|
+
construct(_t, _args) {
|
|
1457
|
+
return shimMj;
|
|
1458
|
+
},
|
|
1459
|
+
get(_t, p) {
|
|
1460
|
+
if (p === "then") return void 0;
|
|
1461
|
+
if (p === "name") return fnName;
|
|
1462
|
+
if (p === "length") return 0;
|
|
1463
|
+
if (p === "bind" || p === "call" || p === "apply" || p === "toString") {
|
|
1464
|
+
return Function.prototype[p].bind(callableFn);
|
|
1465
|
+
}
|
|
1466
|
+
return typeof p === "string" ? shimMj[p] : void 0;
|
|
1467
|
+
}
|
|
1468
|
+
});
|
|
1469
|
+
}
|
|
1470
|
+
function isTargetLike(val) {
|
|
1471
|
+
return typeof val === "object" && val !== null || typeof val === "function";
|
|
1472
|
+
}
|
|
1473
|
+
function createUpdateMemoryFn(shimMj) {
|
|
1474
|
+
const updateMemoryFn = (arg) => {
|
|
1475
|
+
if (typeof arg === "object" && arg !== null && !Array.isArray(arg)) {
|
|
1476
|
+
const entryId = Reflect.get(arg, "entry_id") ?? Reflect.get(arg, "id") ?? Reflect.get(arg, "entryId");
|
|
1477
|
+
if (entryId !== void 0 && entryId !== null) {
|
|
1478
|
+
const adminGroup = shimMj["admin"];
|
|
1479
|
+
const coreGroup2 = shimMj["core"];
|
|
1480
|
+
const fn = (isTargetLike(adminGroup) ? Reflect.get(adminGroup, "updateEntry") ?? Reflect.get(adminGroup, "update_entry") : void 0) ?? (isTargetLike(coreGroup2) ? Reflect.get(coreGroup2, "updateEntry") : void 0);
|
|
1481
|
+
if (typeof fn === "function") {
|
|
1482
|
+
return fn(arg);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
const coreGroup = shimMj["core"];
|
|
1487
|
+
if (isTargetLike(coreGroup)) {
|
|
1488
|
+
const createFn = Reflect.get(coreGroup, "createEntry");
|
|
1489
|
+
if (typeof createFn === "function") {
|
|
1490
|
+
return createFn(arg);
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
return void 0;
|
|
1494
|
+
};
|
|
1495
|
+
Object.assign(updateMemoryFn, {
|
|
1496
|
+
help: () => Promise.resolve({
|
|
1497
|
+
name: "updateMemory",
|
|
1498
|
+
group: "core",
|
|
1499
|
+
description: "Record or update an entry in the memory journal. Pass { title, content, tags, ... } to create an entry, or include entry_id to update an existing entry."
|
|
1500
|
+
}),
|
|
1501
|
+
describe: () => Promise.resolve({
|
|
1502
|
+
name: "updateMemory",
|
|
1503
|
+
group: "core",
|
|
1504
|
+
description: "Record or update an entry in the memory journal. Pass { title, content, tags, ... } to create an entry, or include entry_id to update an existing entry."
|
|
1505
|
+
}),
|
|
1506
|
+
schema: () => {
|
|
1507
|
+
const coreGroup = shimMj["core"];
|
|
1508
|
+
if (isTargetLike(coreGroup)) {
|
|
1509
|
+
const createEntry = Reflect.get(coreGroup, "createEntry");
|
|
1510
|
+
if (isTargetLike(createEntry) && "schema" in createEntry) {
|
|
1511
|
+
const schemaFn = Reflect.get(createEntry, "schema");
|
|
1512
|
+
if (typeof schemaFn === "function") {
|
|
1513
|
+
return schemaFn();
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
return Promise.resolve("unknown");
|
|
1518
|
+
}
|
|
1519
|
+
});
|
|
1520
|
+
return updateMemoryFn;
|
|
1521
|
+
}
|
|
1522
|
+
function wrapDelegatingTool(fn, targetFnGetter) {
|
|
1523
|
+
return new Proxy(fn, {
|
|
1524
|
+
get(target, prop, receiver) {
|
|
1525
|
+
const real = targetFnGetter();
|
|
1526
|
+
if (typeof real === "object" && real !== null || typeof real === "function") {
|
|
1527
|
+
if (prop in real) {
|
|
1528
|
+
return Reflect.get(real, prop);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
return Reflect.get(target, prop, receiver);
|
|
1532
|
+
}
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
var SHIM_TABLES = [
|
|
1536
|
+
"memory_journal",
|
|
1537
|
+
"tags",
|
|
1538
|
+
"entry_tags",
|
|
1539
|
+
"relationships",
|
|
1540
|
+
"entry_anchors",
|
|
1541
|
+
"entry_revisions",
|
|
1542
|
+
"vec_embeddings",
|
|
1543
|
+
"team_flags"
|
|
1544
|
+
];
|
|
1545
|
+
var schemaHelpFn = () => Promise.resolve({
|
|
1546
|
+
group: "schema",
|
|
1547
|
+
description: "Memory Journal Schema: Embedded SQLite database storing journal entries, tags, relationships, code anchors, revisions, vector embeddings, and team flags.",
|
|
1548
|
+
tables: SHIM_TABLES,
|
|
1549
|
+
entrySchema: {
|
|
1550
|
+
id: "number (auto-increment primary key)",
|
|
1551
|
+
content: "string (required, markdown body)",
|
|
1552
|
+
entry_type: ENTRY_TYPES.map((t) => `'${t}'`).join(" | "),
|
|
1553
|
+
timestamp: "string (ISO 8601 timestamp)",
|
|
1554
|
+
is_personal: "boolean (default: true)",
|
|
1555
|
+
significance_type: `optional (${SIGNIFICANCE_TYPES.map((t) => `'${t}'`).join(" | ")})`,
|
|
1556
|
+
tags: "string[] (optional array of kebab-case tags)",
|
|
1557
|
+
workspace_id: "string (required repository/workspace identifier)",
|
|
1558
|
+
project_number: "number (optional GitHub project number)",
|
|
1559
|
+
impact_score: "number (0.0-1.0 blast radius score)",
|
|
1560
|
+
trust_score: "number (0.0-1.0 confidence score)",
|
|
1561
|
+
validation_status: "'passed' | 'none' | 'failed'",
|
|
1562
|
+
auto_context: 'string (optional JSON metadata string, e.g. { "commits": ["<sha>"] })',
|
|
1563
|
+
session_id: "string (optional session tracking id)",
|
|
1564
|
+
relationships: "Array<{ targetId: number, relationType?: string }> (optional entry links)",
|
|
1565
|
+
anchors: "Array<{ anchor_path: string, anchor_type: string, status?: string }> (optional code anchors)"
|
|
1566
|
+
},
|
|
1567
|
+
methods: ["help", "describe", "listTables", "describeTable", "getSchema"],
|
|
1568
|
+
usage: "Call mj.core.createEntry.schema() for entry parameter details, or mj.analytics.getStatistics() for database statistics."
|
|
1569
|
+
});
|
|
1570
|
+
function createSchemaShim(shimMj) {
|
|
1571
|
+
const getStatsFn = () => {
|
|
1572
|
+
const analyticsGroup = shimMj["analytics"];
|
|
1573
|
+
if (isTargetLike(analyticsGroup)) {
|
|
1574
|
+
const fn = Reflect.get(analyticsGroup, "getStatistics");
|
|
1575
|
+
if (typeof fn === "function") {
|
|
1576
|
+
return fn;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
return void 0;
|
|
1580
|
+
};
|
|
1581
|
+
const schemaCallable = function(...args) {
|
|
1582
|
+
const fn = getStatsFn();
|
|
1583
|
+
if (fn !== void 0) {
|
|
1584
|
+
return fn(...args);
|
|
1585
|
+
}
|
|
1586
|
+
return schemaHelpFn();
|
|
1587
|
+
};
|
|
1588
|
+
return new Proxy(schemaCallable, {
|
|
1589
|
+
apply(_t, _thisArg, args) {
|
|
1590
|
+
const fn = getStatsFn();
|
|
1591
|
+
if (fn !== void 0) {
|
|
1592
|
+
return Reflect.apply(fn, void 0, args);
|
|
1593
|
+
}
|
|
1594
|
+
return schemaHelpFn();
|
|
1595
|
+
},
|
|
1596
|
+
get(_t, p) {
|
|
1597
|
+
if (p === "then") return void 0;
|
|
1598
|
+
if (p === "help" || p === "describe") return schemaHelpFn;
|
|
1599
|
+
if (p === "listTables") {
|
|
1600
|
+
return () => Promise.resolve({
|
|
1601
|
+
success: true,
|
|
1602
|
+
tables: SHIM_TABLES
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
if (p === "describeTable" || p === "getSchema") return schemaHelpFn;
|
|
1606
|
+
if (p === "schema") return createSchemaShim(shimMj);
|
|
1607
|
+
if (p === "tables")
|
|
1608
|
+
return SHIM_TABLES;
|
|
1609
|
+
if (p === "memory_journal" || p === "entries" || p === "journal" || p === "memory") {
|
|
1610
|
+
const coreGroup = shimMj["core"];
|
|
1611
|
+
if (isTargetLike(coreGroup)) {
|
|
1612
|
+
const createEntry = Reflect.get(coreGroup, "createEntry");
|
|
1613
|
+
if (isTargetLike(createEntry) && "schema" in createEntry) {
|
|
1614
|
+
const schemaFn = Reflect.get(createEntry, "schema");
|
|
1615
|
+
if (typeof schemaFn === "function") {
|
|
1616
|
+
return schemaFn();
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
return schemaHelpFn();
|
|
1621
|
+
}
|
|
1622
|
+
if (typeof p === "string" && p in Function.prototype) {
|
|
1623
|
+
return Reflect.get(Function.prototype, p);
|
|
1624
|
+
}
|
|
1625
|
+
return Reflect.get(shimMj, p);
|
|
1626
|
+
}
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
function createEmptyFallback(_name) {
|
|
1630
|
+
const emptyIter = function* () {
|
|
1631
|
+
};
|
|
1632
|
+
const fallback = {
|
|
1633
|
+
values: () => emptyIter(),
|
|
1634
|
+
keys: () => emptyIter(),
|
|
1635
|
+
entries: () => emptyIter(),
|
|
1636
|
+
forEach: () => void 0,
|
|
1637
|
+
get: () => void 0,
|
|
1638
|
+
has: () => false,
|
|
1639
|
+
set: () => fallback,
|
|
1640
|
+
delete: () => false,
|
|
1641
|
+
clear: () => void 0,
|
|
1642
|
+
size: 0,
|
|
1643
|
+
length: 0,
|
|
1644
|
+
[Symbol.iterator]: emptyIter,
|
|
1645
|
+
map: () => [],
|
|
1646
|
+
filter: () => [],
|
|
1647
|
+
reduce: (_fn, init) => init ?? [],
|
|
1648
|
+
reduceRight: (_fn, init) => init ?? [],
|
|
1649
|
+
slice: () => [],
|
|
1650
|
+
find: () => void 0,
|
|
1651
|
+
findIndex: () => -1,
|
|
1652
|
+
some: () => false,
|
|
1653
|
+
every: () => true,
|
|
1654
|
+
includes: () => false,
|
|
1655
|
+
indexOf: () => -1,
|
|
1656
|
+
join: () => "",
|
|
1657
|
+
concat: () => [],
|
|
1658
|
+
at: () => void 0,
|
|
1659
|
+
flat: () => [],
|
|
1660
|
+
flatMap: () => []
|
|
1661
|
+
};
|
|
1662
|
+
return new Proxy(fallback, {
|
|
1663
|
+
get(t, p) {
|
|
1664
|
+
if (p in t) return t[p];
|
|
1665
|
+
if (typeof p === "symbol") return void 0;
|
|
1666
|
+
return void 0;
|
|
1667
|
+
}
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
var CONTEXT_COLLECTION_NAMES = [
|
|
1671
|
+
"entries",
|
|
1672
|
+
"results",
|
|
1673
|
+
"projects",
|
|
1674
|
+
"items",
|
|
1675
|
+
"rows",
|
|
1676
|
+
"tables",
|
|
1677
|
+
"flags",
|
|
1678
|
+
"groups",
|
|
1679
|
+
"users",
|
|
1680
|
+
"capabilities",
|
|
1681
|
+
"metrics",
|
|
1682
|
+
"events",
|
|
1683
|
+
"records",
|
|
1684
|
+
"logs",
|
|
1685
|
+
"aliases",
|
|
1686
|
+
"tags",
|
|
1687
|
+
"issues",
|
|
1688
|
+
"pullRequests",
|
|
1689
|
+
"milestones",
|
|
1690
|
+
"columns",
|
|
1691
|
+
"comments",
|
|
1692
|
+
"files",
|
|
1693
|
+
"errors",
|
|
1694
|
+
"backups",
|
|
1695
|
+
"deleted",
|
|
1696
|
+
"updated",
|
|
1697
|
+
"notFound",
|
|
1698
|
+
"history",
|
|
1699
|
+
"relationships",
|
|
1700
|
+
"members",
|
|
1701
|
+
"data",
|
|
1702
|
+
"map",
|
|
1703
|
+
"list"
|
|
1704
|
+
];
|
|
1705
|
+
function createContextProxy(contextObj) {
|
|
1706
|
+
const contextProxy = new Proxy(contextObj ?? {}, {
|
|
1707
|
+
get(target, prop) {
|
|
1708
|
+
if (typeof prop === "symbol") {
|
|
1709
|
+
if (prop === Symbol.toPrimitive) {
|
|
1710
|
+
return (hint) => {
|
|
1711
|
+
if (hint === "number") return NaN;
|
|
1712
|
+
try {
|
|
1713
|
+
return JSON.stringify(target);
|
|
1714
|
+
} catch {
|
|
1715
|
+
return "[object Object]";
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
return void 0;
|
|
1720
|
+
}
|
|
1721
|
+
if (prop === "toString") {
|
|
1722
|
+
return () => {
|
|
1723
|
+
try {
|
|
1724
|
+
return JSON.stringify(target);
|
|
1725
|
+
} catch {
|
|
1726
|
+
return "[object Object]";
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
if (prop === "toJSON") {
|
|
1731
|
+
return () => target;
|
|
1732
|
+
}
|
|
1733
|
+
if (prop === "get" || prop === "getContext" || prop === "get_context") {
|
|
1734
|
+
return (key) => Promise.resolve(
|
|
1735
|
+
wrapResult(
|
|
1736
|
+
typeof key === "string" && key in target ? target[key] : { success: true, ...target }
|
|
1737
|
+
)
|
|
1738
|
+
);
|
|
1739
|
+
}
|
|
1740
|
+
if (prop in target) return target[prop];
|
|
1741
|
+
if (prop === "executeSystemPrompt" || prop === "getPrompt" || prop === "executePrompt") {
|
|
1742
|
+
return (_promptName) => Promise.resolve({
|
|
1743
|
+
success: false,
|
|
1744
|
+
error: `Code Mode cannot execute MCP Prompts via context.${prop}(). Code Mode is for running JavaScript with mj.* tools. Use mj.core.createEntry to save entries.`,
|
|
1745
|
+
code: "VALIDATION_ERROR",
|
|
1746
|
+
category: "validation",
|
|
1747
|
+
recoverable: true
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
if (typeof prop === "string" && CONTEXT_COLLECTION_NAMES.includes(prop)) {
|
|
1751
|
+
return createEmptyFallback();
|
|
1752
|
+
}
|
|
1753
|
+
return target[prop];
|
|
1754
|
+
}
|
|
1755
|
+
});
|
|
1756
|
+
return Object.freeze(contextProxy);
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
// src/codemode/worker/mj-shim-domains.ts
|
|
1760
|
+
function getGroupProp(target, group, prop) {
|
|
1761
|
+
const g = target[group];
|
|
1762
|
+
return typeof g === "object" && g !== null || typeof g === "function" ? Reflect.get(g, prop) : void 0;
|
|
1763
|
+
}
|
|
1764
|
+
var ADAPTER_ITEMS = [
|
|
1765
|
+
{ name: "sqlite", type: "database", driver: "better-sqlite3", status: "connected", primary: true, description: "Primary SQLite storage engine for journal entries, tags, and relationships" },
|
|
1766
|
+
{ name: "sqlite-vec", type: "vector", driver: "sqlite-vec", status: "connected", description: "Native vector embeddings and semantic search engine" },
|
|
1767
|
+
{ name: "team", type: "database", driver: "better-sqlite3", status: "connected", description: "Collaborative team journal database adapter" },
|
|
1768
|
+
{ name: "github", type: "integration", driver: "octokit / gh", status: "connected", description: "GitHub synchronization and issue tracking adapter" }
|
|
1769
|
+
];
|
|
1770
|
+
function createAdaptersShim(prop) {
|
|
1771
|
+
const returnAdapters = () => Promise.resolve({
|
|
1772
|
+
success: true,
|
|
1773
|
+
adapters: ADAPTER_ITEMS,
|
|
1774
|
+
default_adapter: "sqlite",
|
|
1775
|
+
_healing_note: `\u{1F6E0}\uFE0F AUTONOMOUS HEALING: '${prop}' was called. Returned registered database and service adapters successfully.`
|
|
1776
|
+
});
|
|
1777
|
+
const callable = () => returnAdapters();
|
|
1778
|
+
Object.assign(callable, {
|
|
1779
|
+
list: returnAdapters,
|
|
1780
|
+
listAdapters: returnAdapters,
|
|
1781
|
+
list_adapters: returnAdapters,
|
|
1782
|
+
get: returnAdapters
|
|
1783
|
+
});
|
|
1784
|
+
return new Proxy(callable, {
|
|
1785
|
+
apply: () => returnAdapters(),
|
|
1786
|
+
get(t, p) {
|
|
1787
|
+
if (typeof p === "symbol" || p === "then") return void 0;
|
|
1788
|
+
if (p in t) return Reflect.get(t, p);
|
|
1789
|
+
return returnAdapters;
|
|
1790
|
+
}
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
var RESOURCE_SUGGESTIONS2 = {
|
|
1794
|
+
"memory://agent-id": "mj.core.getStatistics() or mj.core.listProjects()",
|
|
1795
|
+
"memory://recent": "mj.core.getRecentEntries()",
|
|
1796
|
+
"memory://statistics": "mj.analytics.getStatistics()",
|
|
1797
|
+
"memory://tags": "mj.core.listTags()",
|
|
1798
|
+
"memory://flags": 'mj.team.teamListFlags({ status: "active" })',
|
|
1799
|
+
"memory://significant": 'mj.search.searchEntries({ sort_by: "importance" })',
|
|
1800
|
+
"memory://insights": "mj.analytics.getCrossProjectInsights()"
|
|
1801
|
+
};
|
|
1802
|
+
function createShimReadResourceHandler() {
|
|
1803
|
+
return (uri) => {
|
|
1804
|
+
let hint = "";
|
|
1805
|
+
if (typeof uri === "string") {
|
|
1806
|
+
const match = Object.entries(RESOURCE_SUGGESTIONS2).find(([k]) => uri.startsWith(k));
|
|
1807
|
+
if (match !== void 0) hint = ` Try: ${match[1]}`;
|
|
1808
|
+
}
|
|
1809
|
+
return Promise.resolve({
|
|
1810
|
+
success: false,
|
|
1811
|
+
error: `Code Mode cannot directly read MCP resources (e.g., memory://briefing) using readResource().${hint} Use the appropriate mj.* tools to query data, or read the resource via standard MCP client requests outside of Code Mode.`,
|
|
1812
|
+
code: "VALIDATION_ERROR",
|
|
1813
|
+
category: "validation",
|
|
1814
|
+
recoverable: true
|
|
1815
|
+
});
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
function createEntriesDomainProxy(target) {
|
|
1819
|
+
const listFunc = getGroupProp(target, "core", "get_recent_entries") ?? getGroupProp(target, "core", "getRecentEntries");
|
|
1820
|
+
if (typeof listFunc !== "function") return void 0;
|
|
1821
|
+
const callableEntries = function(...args) {
|
|
1822
|
+
return listFunc.apply(this, args);
|
|
1823
|
+
};
|
|
1824
|
+
const createFn = getGroupProp(target, "core", "create_entry") ?? getGroupProp(target, "core", "createEntry");
|
|
1825
|
+
const getFn = getGroupProp(target, "core", "get_entry_by_id") ?? getGroupProp(target, "core", "getEntryById");
|
|
1826
|
+
const updateFn = getGroupProp(target, "admin", "update_entry") ?? getGroupProp(target, "admin", "updateEntry") ?? getGroupProp(target, "core", "update_entry") ?? getGroupProp(target, "core", "updateEntry");
|
|
1827
|
+
const deleteFn = getGroupProp(target, "admin", "delete_entry") ?? getGroupProp(target, "admin", "deleteEntry") ?? getGroupProp(target, "core", "delete_entry") ?? getGroupProp(target, "core", "deleteEntry");
|
|
1828
|
+
const searchFn = getGroupProp(target, "search", "search_entries") ?? getGroupProp(target, "search", "searchEntries") ?? getGroupProp(target, "core", "search_entries") ?? getGroupProp(target, "core", "searchEntries");
|
|
1829
|
+
Object.assign(callableEntries, {
|
|
1830
|
+
create: createFn,
|
|
1831
|
+
createEntry: createFn,
|
|
1832
|
+
create_entry: createFn,
|
|
1833
|
+
add: createFn,
|
|
1834
|
+
push: createFn,
|
|
1835
|
+
get: getFn,
|
|
1836
|
+
getEntryById: getFn,
|
|
1837
|
+
get_entry_by_id: getFn,
|
|
1838
|
+
update: updateFn,
|
|
1839
|
+
updateEntry: updateFn,
|
|
1840
|
+
update_entry: updateFn,
|
|
1841
|
+
delete: deleteFn,
|
|
1842
|
+
deleteEntry: deleteFn,
|
|
1843
|
+
delete_entry: deleteFn,
|
|
1844
|
+
search: searchFn,
|
|
1845
|
+
searchEntries: searchFn,
|
|
1846
|
+
search_entries: searchFn,
|
|
1847
|
+
list: listFunc,
|
|
1848
|
+
listEntries: listFunc,
|
|
1849
|
+
list_entries: listFunc,
|
|
1850
|
+
getRecent: listFunc,
|
|
1851
|
+
getRecentEntries: listFunc,
|
|
1852
|
+
get_recent_entries: listFunc
|
|
1853
|
+
});
|
|
1854
|
+
return new Proxy(callableEntries, {
|
|
1855
|
+
get(targetFn, p, receiver) {
|
|
1856
|
+
if (p in targetFn) return Reflect.get(targetFn, p, receiver);
|
|
1857
|
+
if (typeof p === "string") {
|
|
1858
|
+
const pLower = p.toLowerCase().replace(/_/g, "");
|
|
1859
|
+
if ((pLower.includes("search") || pLower.includes("query") || pLower.includes("find")) && typeof searchFn === "function") return searchFn;
|
|
1860
|
+
if ((pLower.includes("create") || pLower.includes("add") || pLower.includes("insert") || pLower.includes("append")) && typeof createFn === "function") return createFn;
|
|
1861
|
+
if ((pLower.includes("get") || pLower.includes("fetch") || pLower.includes("read") || pLower.includes("byid")) && typeof getFn === "function") return getFn;
|
|
1862
|
+
if ((pLower.includes("update") || pLower.includes("edit") || pLower.includes("patch")) && typeof updateFn === "function") return updateFn;
|
|
1863
|
+
if ((pLower.includes("delete") || pLower.includes("remove")) && typeof deleteFn === "function") return deleteFn;
|
|
1864
|
+
if (pLower.includes("recent") || pLower.includes("list") || pLower.includes("all")) return listFunc;
|
|
1865
|
+
const methodOnCore = getGroupProp(target, "core", p) ?? getGroupProp(target, "search", p) ?? getGroupProp(target, "admin", p);
|
|
1866
|
+
if (typeof methodOnCore === "function") return methodOnCore;
|
|
1867
|
+
}
|
|
1868
|
+
return Reflect.get(targetFn, p, receiver);
|
|
1869
|
+
}
|
|
1870
|
+
});
|
|
1871
|
+
}
|
|
1872
|
+
function createGetReadFindInterceptor(target, shimMj) {
|
|
1873
|
+
const getFn = getGroupProp(target, "core", "get_entry_by_id") ?? getGroupProp(target, "core", "getEntryById");
|
|
1874
|
+
const searchFn = getGroupProp(target, "search", "search_entries") ?? getGroupProp(target, "search", "searchEntries");
|
|
1875
|
+
return (arg) => {
|
|
1876
|
+
if (arg === void 0) return Promise.resolve(shimMj);
|
|
1877
|
+
if (typeof arg === "number" || typeof arg === "string") {
|
|
1878
|
+
const parsedId = Number(arg);
|
|
1879
|
+
if (!Number.isNaN(parsedId)) {
|
|
1880
|
+
return typeof getFn === "function" ? getFn({ entry_id: parsedId }) : void 0;
|
|
1881
|
+
}
|
|
1882
|
+
if (typeof arg === "string") return Promise.resolve(shimMj);
|
|
1883
|
+
}
|
|
1884
|
+
if (arg !== null && typeof arg === "object") {
|
|
1885
|
+
if ("entry_id" in arg || "id" in arg) {
|
|
1886
|
+
return typeof getFn === "function" ? getFn(arg) : void 0;
|
|
1887
|
+
}
|
|
1888
|
+
if ("query" in arg || "tags" in arg || "search" in arg || "text" in arg || "q" in arg) {
|
|
1889
|
+
return typeof searchFn === "function" ? searchFn(arg) : void 0;
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
return typeof getFn === "function" ? getFn(arg) : void 0;
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1895
|
+
function createShimProjectsDomain(target, shimMj) {
|
|
1896
|
+
const baseProjectsProxy = target["projects"];
|
|
1897
|
+
const createFn = getGroupProp(target, "core", "create_entry") ?? getGroupProp(target, "core", "createEntry");
|
|
1898
|
+
const insightsFn = getGroupProp(target, "analytics", "get_cross_project_insights") ?? getGroupProp(target, "analytics", "getCrossProjectInsights");
|
|
1899
|
+
const projectsFn = function(...args) {
|
|
1900
|
+
if (typeof baseProjectsProxy === "function") {
|
|
1901
|
+
return baseProjectsProxy.apply(this, args);
|
|
1902
|
+
}
|
|
1903
|
+
return Promise.resolve({ success: true, projects: {}, items: [], data: [] });
|
|
1904
|
+
};
|
|
1905
|
+
return new Proxy(projectsFn, {
|
|
1906
|
+
apply(_t, thisArg, args) {
|
|
1907
|
+
if (typeof baseProjectsProxy === "function") {
|
|
1908
|
+
return baseProjectsProxy.apply(thisArg, args);
|
|
1909
|
+
}
|
|
1910
|
+
return Promise.resolve({ success: true, projects: [] });
|
|
1911
|
+
},
|
|
1912
|
+
get(_t, p) {
|
|
1913
|
+
if (typeof p === "symbol" || p === "then") return void 0;
|
|
1914
|
+
if (p === "entries") return { create: createFn, add: createFn };
|
|
1915
|
+
if (p === "insights" && typeof insightsFn === "function") {
|
|
1916
|
+
return (...args) => insightsFn(...args);
|
|
1917
|
+
}
|
|
1918
|
+
if (typeof baseProjectsProxy === "function" || typeof baseProjectsProxy === "object" && baseProjectsProxy !== null) {
|
|
1919
|
+
return Reflect.get(baseProjectsProxy, p);
|
|
1920
|
+
}
|
|
1921
|
+
return createCallableShim(shimMj);
|
|
1922
|
+
}
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
var STATS_METHOD_KEYS = /* @__PURE__ */ new Set([
|
|
1926
|
+
"getStatistics",
|
|
1927
|
+
"getStats",
|
|
1928
|
+
"stats",
|
|
1929
|
+
"info",
|
|
1930
|
+
"getInfo",
|
|
1931
|
+
"getDatabaseInfo",
|
|
1932
|
+
"databaseInfo",
|
|
1933
|
+
"getHealth",
|
|
1934
|
+
"health",
|
|
1935
|
+
"status",
|
|
1936
|
+
"getStatus",
|
|
1937
|
+
"serverInfo",
|
|
1938
|
+
"server_info",
|
|
1939
|
+
"serverHealth",
|
|
1940
|
+
"server_health",
|
|
1941
|
+
"serverStatus",
|
|
1942
|
+
"server_status",
|
|
1943
|
+
"healthCheck",
|
|
1944
|
+
"health_check",
|
|
1945
|
+
"diagnostics",
|
|
1946
|
+
"getDiagnostics",
|
|
1947
|
+
"systemInfo",
|
|
1948
|
+
"system_info",
|
|
1949
|
+
"adapters",
|
|
1950
|
+
"listAdapters",
|
|
1951
|
+
"list_adapters",
|
|
1952
|
+
"getAdapters",
|
|
1953
|
+
"get_adapters"
|
|
1954
|
+
]);
|
|
1955
|
+
function createDbDomainProxy(target, shimMj) {
|
|
1956
|
+
const getStatsFn = getGroupProp(target, "analytics", "getStatistics") ?? getGroupProp(target, "analytics", "get_statistics");
|
|
1957
|
+
return new Proxy({}, {
|
|
1958
|
+
get(_t, dbProp) {
|
|
1959
|
+
if (typeof dbProp === "symbol" || dbProp === "then") return void 0;
|
|
1960
|
+
if (dbProp === "schema") return createSchemaShim(shimMj);
|
|
1961
|
+
if (dbProp === "help" || dbProp === "describe") {
|
|
1962
|
+
const helpFn = target["help"];
|
|
1963
|
+
return () => typeof helpFn === "function" ? helpFn() : void 0;
|
|
1964
|
+
}
|
|
1965
|
+
if (dbProp === "prepare" || dbProp === "stmt" || dbProp === "statement") {
|
|
1966
|
+
return (sql) => createPreparedStatementShim(typeof sql === "string" ? sql : "", shimMj);
|
|
1967
|
+
}
|
|
1968
|
+
if (dbProp === "exec") {
|
|
1969
|
+
return (sql) => {
|
|
1970
|
+
const stmt = createPreparedStatementShim(typeof sql === "string" ? sql : "", shimMj);
|
|
1971
|
+
const runFn = stmt["run"];
|
|
1972
|
+
return typeof runFn === "function" ? runFn() : void 0;
|
|
1973
|
+
};
|
|
1974
|
+
}
|
|
1975
|
+
if (dbProp === "query" || dbProp === "raw") {
|
|
1976
|
+
return (sql) => {
|
|
1977
|
+
const stmt = createPreparedStatementShim(typeof sql === "string" ? sql : "", shimMj);
|
|
1978
|
+
const allFn = stmt["all"];
|
|
1979
|
+
return typeof allFn === "function" ? allFn() : void 0;
|
|
1980
|
+
};
|
|
1981
|
+
}
|
|
1982
|
+
if (dbProp === "close" || dbProp === "dispose" || dbProp === "disconnect") {
|
|
1983
|
+
return () => ({ success: true });
|
|
1984
|
+
}
|
|
1985
|
+
if (dbProp === "getDatabase" || dbProp === "getDb" || dbProp === "get_database" || dbProp === "get_db") {
|
|
1986
|
+
return () => shimMj;
|
|
1987
|
+
}
|
|
1988
|
+
if (dbProp === "ping") return () => Promise.resolve({ success: true, status: "pong" });
|
|
1989
|
+
if (dbProp === "version") {
|
|
1990
|
+
return () => Promise.resolve({ success: true, version: VERSION, name: "memory-journal-mcp" });
|
|
1991
|
+
}
|
|
1992
|
+
if (STATS_METHOD_KEYS.has(dbProp) && typeof getStatsFn === "function") return getStatsFn;
|
|
1993
|
+
return (..._args) => Promise.resolve({
|
|
1994
|
+
success: false,
|
|
1995
|
+
error: `Direct SQLite database access 'mj.db.${dbProp}()' is not available in Code Mode sandbox. Use high-level API methods instead: mj.core.createEntry({ ... }), mj.core.getRecentEntries({ ... }), or mj.search.searchEntries({ ... }).`,
|
|
1996
|
+
code: "VALIDATION_ERROR",
|
|
1997
|
+
category: "validation",
|
|
1998
|
+
suggestion: "Use mj.core or mj.search methods.",
|
|
1999
|
+
recoverable: true
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
function createSystemDatabaseDomainProxy(target, shimMj) {
|
|
2005
|
+
if (typeof target["system"] === "function" || typeof target["system"] === "object" && target["system"] !== null) {
|
|
2006
|
+
return target["system"];
|
|
2007
|
+
}
|
|
2008
|
+
const getStatsFn = getGroupProp(target, "analytics", "getStatistics") ?? getGroupProp(target, "analytics", "get_statistics");
|
|
2009
|
+
const dbShim = {
|
|
2010
|
+
ping: () => Promise.resolve({ success: true, status: "pong" }),
|
|
2011
|
+
version: () => Promise.resolve({ success: true, version: VERSION, name: "memory-journal-mcp" })
|
|
2012
|
+
};
|
|
2013
|
+
for (const k of STATS_METHOD_KEYS) dbShim[k] = getStatsFn;
|
|
2014
|
+
return new Proxy(dbShim, {
|
|
2015
|
+
get(t, p) {
|
|
2016
|
+
if (typeof p === "symbol" || p === "then") return void 0;
|
|
2017
|
+
if (typeof p === "string" && p in t) return t[p];
|
|
2018
|
+
if (typeof getStatsFn === "function") return getStatsFn;
|
|
2019
|
+
return createCallableShim(shimMj);
|
|
2020
|
+
}
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
function createSearchDomainProxy(target) {
|
|
2024
|
+
const searchGroup = target["search"];
|
|
2025
|
+
if ((typeof searchGroup !== "object" || searchGroup === null) && typeof searchGroup !== "function") {
|
|
2026
|
+
return void 0;
|
|
2027
|
+
}
|
|
2028
|
+
const searchFunc = Reflect.get(searchGroup, "search_entries") ?? Reflect.get(searchGroup, "searchEntries");
|
|
2029
|
+
if (typeof searchFunc === "function") {
|
|
2030
|
+
const callableSearch = function(...args) {
|
|
2031
|
+
return searchFunc.apply(this, args);
|
|
2032
|
+
};
|
|
2033
|
+
Object.assign(callableSearch, searchGroup, {
|
|
2034
|
+
search: searchFunc,
|
|
2035
|
+
query: searchFunc,
|
|
2036
|
+
queryEntries: searchFunc,
|
|
2037
|
+
query_entries: searchFunc,
|
|
2038
|
+
searchEntries: searchFunc,
|
|
2039
|
+
search_entries: searchFunc,
|
|
2040
|
+
find: searchFunc,
|
|
2041
|
+
findEntries: searchFunc,
|
|
2042
|
+
find_entries: searchFunc
|
|
2043
|
+
});
|
|
2044
|
+
return new Proxy(callableSearch, {
|
|
2045
|
+
get(targetFn, p, receiver) {
|
|
2046
|
+
if (p in targetFn) return Reflect.get(targetFn, p, receiver);
|
|
2047
|
+
return Reflect.get(searchGroup, p, receiver);
|
|
2048
|
+
}
|
|
2049
|
+
});
|
|
2050
|
+
}
|
|
2051
|
+
return searchGroup;
|
|
2052
|
+
}
|
|
2053
|
+
function createAppendInterceptor(target) {
|
|
2054
|
+
const createEntry = getGroupProp(target, "core", "createEntry");
|
|
2055
|
+
if (typeof createEntry !== "function") return void 0;
|
|
2056
|
+
return (arg1, arg2, arg3) => {
|
|
2057
|
+
const tags = Array.isArray(arg1) ? arg1 : [typeof arg1 === "string" ? arg1 : "test"];
|
|
2058
|
+
const content = typeof arg2 === "string" ? arg2 : arg2 !== null && arg2 !== void 0 ? JSON.stringify(arg2) : "";
|
|
2059
|
+
const metadata = typeof arg3 === "object" && arg3 !== null && !Array.isArray(arg3) ? { ...arg3 } : void 0;
|
|
2060
|
+
const typeVal = metadata?.["type"];
|
|
2061
|
+
const type = typeof typeVal === "string" && typeVal !== "" ? typeVal : "test_entry";
|
|
2062
|
+
if (metadata !== void 0 && "type" in metadata) delete metadata["type"];
|
|
2063
|
+
return createEntry({ type, tags, content, metadata });
|
|
2064
|
+
};
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
// src/codemode/worker/mj-shim-proxy.ts
|
|
2068
|
+
var SELF_REFERENTIAL_PROPS = /* @__PURE__ */ new Set([
|
|
2069
|
+
"mj",
|
|
2070
|
+
"journal",
|
|
2071
|
+
"journals",
|
|
2072
|
+
"journal_entries",
|
|
2073
|
+
"journalEntries",
|
|
2074
|
+
"memory",
|
|
2075
|
+
"memory_journal",
|
|
2076
|
+
"memory_journal_mcp",
|
|
2077
|
+
"sqlite",
|
|
2078
|
+
"sqlite3",
|
|
2079
|
+
"m",
|
|
2080
|
+
"env",
|
|
2081
|
+
"agent",
|
|
2082
|
+
"mcp",
|
|
2083
|
+
"mcpx",
|
|
2084
|
+
"mc",
|
|
2085
|
+
"memoryJournal",
|
|
2086
|
+
"MemoryJournal",
|
|
2087
|
+
"mjJournal",
|
|
2088
|
+
"mjClient",
|
|
2089
|
+
"mj_client",
|
|
2090
|
+
"app",
|
|
2091
|
+
"tools",
|
|
2092
|
+
"tool",
|
|
2093
|
+
"api",
|
|
2094
|
+
"client",
|
|
2095
|
+
"sdk",
|
|
2096
|
+
"service",
|
|
2097
|
+
"services",
|
|
2098
|
+
"kernel",
|
|
2099
|
+
"node",
|
|
2100
|
+
"default"
|
|
2101
|
+
]);
|
|
2102
|
+
var EXECUTE_CODE_PROPS = /* @__PURE__ */ new Set([
|
|
2103
|
+
"execute",
|
|
2104
|
+
"executeCode",
|
|
2105
|
+
"execute_code",
|
|
2106
|
+
"mj_execute_code",
|
|
2107
|
+
"mjExecuteCode"
|
|
2108
|
+
]);
|
|
2109
|
+
var ADAPTER_PROPS = /* @__PURE__ */ new Set([
|
|
2110
|
+
"adapters",
|
|
2111
|
+
"list_adapters",
|
|
2112
|
+
"listAdapters",
|
|
2113
|
+
"get_adapters",
|
|
2114
|
+
"getAdapters"
|
|
2115
|
+
]);
|
|
2116
|
+
var READ_RESOURCE_PROPS = /* @__PURE__ */ new Set([
|
|
2117
|
+
"readResource",
|
|
2118
|
+
"read_resource",
|
|
2119
|
+
"memory_read_resource",
|
|
2120
|
+
"memoryReadResource",
|
|
2121
|
+
"getResource",
|
|
2122
|
+
"get_resource"
|
|
2123
|
+
]);
|
|
2124
|
+
var BRIEFING_PROPS = /* @__PURE__ */ new Set([
|
|
2125
|
+
"loadBriefing",
|
|
2126
|
+
"load_briefing",
|
|
2127
|
+
"getBriefing",
|
|
2128
|
+
"get_briefing"
|
|
2129
|
+
]);
|
|
2130
|
+
var CREATE_ENTRY_HALLUCINATION_PROPS = /* @__PURE__ */ new Set([
|
|
2131
|
+
"addEntry",
|
|
2132
|
+
"create_entry",
|
|
2133
|
+
"createEntry",
|
|
2134
|
+
"create",
|
|
2135
|
+
"add",
|
|
2136
|
+
"log",
|
|
2137
|
+
"insertEntry",
|
|
2138
|
+
"insert_entry",
|
|
2139
|
+
"insert",
|
|
2140
|
+
"add_entry",
|
|
2141
|
+
"newEntry",
|
|
2142
|
+
"new_entry",
|
|
2143
|
+
"logEntry",
|
|
2144
|
+
"log_entry",
|
|
2145
|
+
"saveEntry",
|
|
2146
|
+
"save_entry",
|
|
2147
|
+
"writeEntry",
|
|
2148
|
+
"write_entry",
|
|
2149
|
+
"appendEntry",
|
|
2150
|
+
"append_entry",
|
|
2151
|
+
"createMemory",
|
|
2152
|
+
"create_memory",
|
|
2153
|
+
"addMemory",
|
|
2154
|
+
"add_memory",
|
|
2155
|
+
"recordMemory",
|
|
2156
|
+
"record_memory"
|
|
2157
|
+
]);
|
|
2158
|
+
var UPDATE_MEMORY_PROPS = /* @__PURE__ */ new Set([
|
|
2159
|
+
"updateMemory",
|
|
2160
|
+
"update_memory",
|
|
2161
|
+
"setMemory",
|
|
2162
|
+
"set_memory",
|
|
2163
|
+
"updateJournal",
|
|
2164
|
+
"update_journal"
|
|
2165
|
+
]);
|
|
2166
|
+
var FACTORY_SHIM_PROPS = /* @__PURE__ */ new Set([
|
|
2167
|
+
"load",
|
|
2168
|
+
"loadJournal",
|
|
2169
|
+
"loadMemory",
|
|
2170
|
+
"load_memory",
|
|
2171
|
+
"init",
|
|
2172
|
+
"initialize",
|
|
2173
|
+
"connect",
|
|
2174
|
+
"getJournal",
|
|
2175
|
+
"get_journal",
|
|
2176
|
+
"load_journal",
|
|
2177
|
+
"getInstance",
|
|
2178
|
+
"get_instance",
|
|
2179
|
+
"createInstance",
|
|
2180
|
+
"create_instance",
|
|
2181
|
+
"initInstance",
|
|
2182
|
+
"init_instance",
|
|
2183
|
+
"getClient",
|
|
2184
|
+
"get_client",
|
|
2185
|
+
"createClient",
|
|
2186
|
+
"create_client",
|
|
2187
|
+
"initClient",
|
|
2188
|
+
"init_client",
|
|
2189
|
+
"getService",
|
|
2190
|
+
"get_service",
|
|
2191
|
+
"createService",
|
|
2192
|
+
"create_service",
|
|
2193
|
+
"createJournal",
|
|
2194
|
+
"create_journal",
|
|
2195
|
+
"open",
|
|
2196
|
+
"start",
|
|
2197
|
+
"getDatabase",
|
|
2198
|
+
"get_database",
|
|
2199
|
+
"getDb",
|
|
2200
|
+
"get_db",
|
|
2201
|
+
"connectToDatabase",
|
|
2202
|
+
"connect_to_database",
|
|
2203
|
+
"openDatabase",
|
|
2204
|
+
"open_database",
|
|
2205
|
+
"create"
|
|
2206
|
+
]);
|
|
2207
|
+
var LIFECYCLE_PROPS = /* @__PURE__ */ new Set([
|
|
2208
|
+
"close",
|
|
2209
|
+
"dispose",
|
|
2210
|
+
"disconnect",
|
|
2211
|
+
"end",
|
|
2212
|
+
"destroy",
|
|
2213
|
+
"quit",
|
|
2214
|
+
"exit",
|
|
2215
|
+
"terminate",
|
|
2216
|
+
"clear",
|
|
2217
|
+
"reset"
|
|
2218
|
+
]);
|
|
2219
|
+
var DB_CONSTRUCTOR_PROPS = /* @__PURE__ */ new Set([
|
|
2220
|
+
"Database",
|
|
2221
|
+
"Sqlite3",
|
|
2222
|
+
"BetterSqlite3",
|
|
2223
|
+
"better_sqlite3",
|
|
2224
|
+
"betterSqlite3"
|
|
2225
|
+
]);
|
|
2226
|
+
function getGroupProp2(target, group, prop) {
|
|
2227
|
+
const g = target[group];
|
|
2228
|
+
return typeof g === "object" && g !== null || typeof g === "function" ? Reflect.get(g, prop) : void 0;
|
|
2229
|
+
}
|
|
2230
|
+
function createShimMjProxy(options) {
|
|
2231
|
+
const { mjApi, safeFsShim, executeCodeFnRef, getUpdateMemoryFn } = options;
|
|
2232
|
+
const shimMj = new Proxy({}, {
|
|
2233
|
+
get(_fakeTarget, prop) {
|
|
2234
|
+
const target = mjApi;
|
|
2235
|
+
if (typeof prop === "string" && SELF_REFERENTIAL_PROPS.has(prop)) return shimMj;
|
|
2236
|
+
if (prop === "context") return mjApi["context"];
|
|
2237
|
+
if (prop === "getContext" || prop === "get_context") return mjApi["getContext"];
|
|
2238
|
+
if (prop === "schema") return createSchemaShim(shimMj);
|
|
2239
|
+
if (typeof prop === "string" && EXECUTE_CODE_PROPS.has(prop)) {
|
|
2240
|
+
return (arg) => {
|
|
2241
|
+
if (executeCodeFnRef.current !== void 0) return executeCodeFnRef.current(arg);
|
|
2242
|
+
if ("codemode" in target) {
|
|
2243
|
+
const fn = getGroupProp2(target, "codemode", "mjExecuteCode") ?? getGroupProp2(target, "codemode", "executeCode");
|
|
2244
|
+
if (typeof fn === "function") return fn(arg);
|
|
2245
|
+
}
|
|
2246
|
+
return Promise.resolve({ success: true });
|
|
2247
|
+
};
|
|
2248
|
+
}
|
|
2249
|
+
if (typeof prop === "string" && ADAPTER_PROPS.has(prop)) return createAdaptersShim(prop);
|
|
2250
|
+
if (typeof prop === "string" && READ_RESOURCE_PROPS.has(prop)) return createShimReadResourceHandler();
|
|
2251
|
+
if (prop === "logger") return consoleShim;
|
|
2252
|
+
if (typeof prop === "string" && BRIEFING_PROPS.has(prop) && "core" in target) {
|
|
2253
|
+
const fn = getGroupProp2(target, "core", "getRecentEntries") ?? getGroupProp2(target, "core", "get_recent_entries");
|
|
2254
|
+
if (typeof fn === "function") {
|
|
2255
|
+
return (args) => fn({ limit: 10, sort_by: "importance", ...args });
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
if ((prop === "entries" || prop === "entry") && "core" in target) {
|
|
2259
|
+
const entriesProxy = createEntriesDomainProxy(target);
|
|
2260
|
+
if (entriesProxy !== void 0) return entriesProxy;
|
|
2261
|
+
}
|
|
2262
|
+
if (typeof prop === "string" && CREATE_ENTRY_HALLUCINATION_PROPS.has(prop) && "core" in target) {
|
|
2263
|
+
return getGroupProp2(target, "core", "create_entry") ?? getGroupProp2(target, "core", "createEntry");
|
|
2264
|
+
}
|
|
2265
|
+
if (typeof prop === "string" && UPDATE_MEMORY_PROPS.has(prop)) return getUpdateMemoryFn();
|
|
2266
|
+
if (prop === "saveMemory" || prop === "save_memory") {
|
|
2267
|
+
return (arg) => arg !== void 0 && arg !== null ? getUpdateMemoryFn()(arg) : Promise.resolve({ success: true });
|
|
2268
|
+
}
|
|
2269
|
+
if ((prop === "get" || prop === "read" || prop === "find" || prop === "fetch") && "core" in target && "search" in target) {
|
|
2270
|
+
return createGetReadFindInterceptor(target, shimMj);
|
|
2271
|
+
}
|
|
2272
|
+
if ((prop === "update" || prop === "edit") && "core" in target) {
|
|
2273
|
+
return getGroupProp2(target, "core", "update_entry") ?? getGroupProp2(target, "core", "updateEntry");
|
|
2274
|
+
}
|
|
2275
|
+
if ((prop === "delete" || prop === "remove") && "core" in target) {
|
|
2276
|
+
return getGroupProp2(target, "core", "delete_entry") ?? getGroupProp2(target, "core", "deleteEntry");
|
|
2277
|
+
}
|
|
2278
|
+
if (typeof prop === "string" && FACTORY_SHIM_PROPS.has(prop)) {
|
|
2279
|
+
return createCallableShim(shimMj, "factoryFn");
|
|
2280
|
+
}
|
|
2281
|
+
if (prop === "projects" || prop === "project") return createShimProjectsDomain(target, shimMj);
|
|
2282
|
+
if (prop === "db") {
|
|
2283
|
+
return "core" in target ? createDbDomainProxy(target, shimMj) : createSystemDatabaseDomainProxy(target, shimMj);
|
|
2284
|
+
}
|
|
2285
|
+
if (prop === "prepare" || prop === "stmt" || prop === "statement") {
|
|
2286
|
+
return (sql) => createPreparedStatementShim(typeof sql === "string" ? sql : "", shimMj);
|
|
2287
|
+
}
|
|
2288
|
+
if (prop === "query" || prop === "raw") {
|
|
2289
|
+
return (sql) => {
|
|
2290
|
+
const stmt = createPreparedStatementShim(typeof sql === "string" ? sql : "", shimMj);
|
|
2291
|
+
const allFn = stmt["all"];
|
|
2292
|
+
return typeof allFn === "function" ? allFn() : void 0;
|
|
2293
|
+
};
|
|
2294
|
+
}
|
|
2295
|
+
if (prop === "exec") {
|
|
2296
|
+
return (sql) => {
|
|
2297
|
+
const stmt = createPreparedStatementShim(typeof sql === "string" ? sql : "", shimMj);
|
|
2298
|
+
const runFn = stmt["run"];
|
|
2299
|
+
return typeof runFn === "function" ? runFn() : void 0;
|
|
2300
|
+
};
|
|
2301
|
+
}
|
|
2302
|
+
if (typeof prop === "string" && LIFECYCLE_PROPS.has(prop)) return () => ({ success: true });
|
|
2303
|
+
if (prop === "execSync" || prop === "spawnSync" || prop === "execFileSync") return () => "";
|
|
2304
|
+
if (prop === "spawn" || prop === "fork" || prop === "execFile") {
|
|
2305
|
+
return (_cmd, cbOrOptions, maybeCb) => {
|
|
2306
|
+
const cb = typeof cbOrOptions === "function" ? cbOrOptions : typeof maybeCb === "function" ? maybeCb : void 0;
|
|
2307
|
+
if (cb !== void 0) {
|
|
2308
|
+
try {
|
|
2309
|
+
cb(null, "", "");
|
|
2310
|
+
} catch {
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
const noop = () => {
|
|
2314
|
+
};
|
|
2315
|
+
return { on: noop, stdout: { on: noop }, stderr: { on: noop }, kill: () => true, status: 0, output: ["", "", ""] };
|
|
2316
|
+
};
|
|
2317
|
+
}
|
|
2318
|
+
if (prop === "fs" || prop === "__safeFs" || prop === "safeFs") return safeFsShim;
|
|
2319
|
+
if (prop === "path" || prop === "__path") return pathShim;
|
|
2320
|
+
if (prop === "existsSync") return safeFsShim.existsSync;
|
|
2321
|
+
if (prop === "readFileSync" || prop === "readFile") return safeFsShim.readFileSync;
|
|
2322
|
+
if (prop === "writeFileSync" || prop === "writeFile" || prop === "mkdirSync" || prop === "appendFileSync" || prop === "unlinkSync") {
|
|
2323
|
+
return () => void 0;
|
|
2324
|
+
}
|
|
2325
|
+
if (prop === "statSync") return safeFsShim.statSync;
|
|
2326
|
+
if (prop === "stat") return safeFsShim.stat;
|
|
2327
|
+
if (prop === "readdirSync") return () => [];
|
|
2328
|
+
if (prop === "join" || prop === "resolve" || prop === "basename" || prop === "dirname" || prop === "extname") {
|
|
2329
|
+
return (...parts) => parts.filter((p) => typeof p === "string").join("/");
|
|
2330
|
+
}
|
|
2331
|
+
if (prop === "promisify") return (fn) => fn;
|
|
2332
|
+
if (prop === "format" || prop === "inspect") return (...args) => args.map(String).join(" ");
|
|
2333
|
+
if (typeof prop === "string" && DB_CONSTRUCTOR_PROPS.has(prop)) return createCallableShim(shimMj);
|
|
2334
|
+
if (prop === "database" || prop === "system") return createSystemDatabaseDomainProxy(target, shimMj);
|
|
2335
|
+
if (prop === "tags" || prop === "tag") return target["tags"];
|
|
2336
|
+
if ((prop === "getProjects" || prop === "listProjects" || prop === "searchProjects") && "analytics" in target) {
|
|
2337
|
+
return getGroupProp2(target, "analytics", "get_cross_project_insights") ?? getGroupProp2(target, "analytics", "getCrossProjectInsights");
|
|
2338
|
+
}
|
|
2339
|
+
if (prop === "search" && "search" in target) {
|
|
2340
|
+
const searchDomain = createSearchDomainProxy(target);
|
|
2341
|
+
if (searchDomain !== void 0) return searchDomain;
|
|
2342
|
+
}
|
|
2343
|
+
if (prop === "append" && "core" in target) {
|
|
2344
|
+
const appendFn = createAppendInterceptor(target);
|
|
2345
|
+
if (appendFn !== void 0) return appendFn;
|
|
2346
|
+
}
|
|
2347
|
+
if (typeof prop === "string" && prop.includes("_")) {
|
|
2348
|
+
const camelProp = prop.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
2349
|
+
if (camelProp !== prop) {
|
|
2350
|
+
const mapping = DB_TO_JOURNAL[camelProp];
|
|
2351
|
+
if (mapping !== void 0) {
|
|
2352
|
+
const [group, method] = mapping;
|
|
2353
|
+
if (group in target) return getGroupProp2(target, group, method);
|
|
2354
|
+
}
|
|
2355
|
+
if (camelProp in target) return target[camelProp];
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
if (typeof prop === "string") {
|
|
2359
|
+
const mapping = DB_TO_JOURNAL[prop];
|
|
2360
|
+
if (mapping !== void 0) {
|
|
2361
|
+
const [group, method] = mapping;
|
|
2362
|
+
if (group in target) return getGroupProp2(target, group, method);
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
return typeof prop === "string" ? target[prop] : void 0;
|
|
2366
|
+
},
|
|
2367
|
+
has: (_fakeTarget, prop) => prop in mjApi,
|
|
2368
|
+
ownKeys: () => Reflect.ownKeys(mjApi),
|
|
2369
|
+
getOwnPropertyDescriptor(_fakeTarget, prop) {
|
|
2370
|
+
const desc = Reflect.getOwnPropertyDescriptor(mjApi, prop);
|
|
2371
|
+
return desc ? { ...desc, configurable: true } : void 0;
|
|
2372
|
+
},
|
|
2373
|
+
set: () => false,
|
|
2374
|
+
defineProperty: () => false,
|
|
2375
|
+
deleteProperty: () => false,
|
|
2376
|
+
setPrototypeOf: () => false,
|
|
2377
|
+
isExtensible: () => true,
|
|
2378
|
+
preventExtensions: () => false
|
|
2379
|
+
});
|
|
2380
|
+
return shimMj;
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
// src/codemode/worker/sandbox-globals.ts
|
|
2384
|
+
function getGroupMethod(shimMj, group, method) {
|
|
2385
|
+
const g = shimMj[group];
|
|
2386
|
+
if (typeof g === "object" && g !== null || typeof g === "function") {
|
|
2387
|
+
const fn = Reflect.get(g, method);
|
|
2388
|
+
if (typeof fn === "function") {
|
|
2389
|
+
return fn;
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
return void 0;
|
|
2393
|
+
}
|
|
2394
|
+
function makeDelegatingTool(shimMj, group, method) {
|
|
2395
|
+
return wrapDelegatingTool(
|
|
2396
|
+
(arg) => getGroupMethod(shimMj, group, method)?.(arg),
|
|
2397
|
+
() => getGroupMethod(shimMj, group, method)
|
|
2398
|
+
);
|
|
2399
|
+
}
|
|
2400
|
+
function createProcessOperationFn(shimMj) {
|
|
2401
|
+
return (arg) => {
|
|
2402
|
+
if (typeof arg === "object" && arg !== null && !Array.isArray(arg)) {
|
|
2403
|
+
const op = Reflect.get(arg, "operation") ?? Reflect.get(arg, "op") ?? Reflect.get(arg, "action") ?? Reflect.get(arg, "type");
|
|
2404
|
+
if (op === "add_entry" || op === "create_entry" || op === "create" || op === "add" || op === "insert") {
|
|
2405
|
+
return getGroupMethod(shimMj, "core", "createEntry")?.(arg);
|
|
2406
|
+
}
|
|
2407
|
+
if (op === "update_entry" || op === "update" || op === "edit") {
|
|
2408
|
+
return getGroupMethod(shimMj, "admin", "updateEntry")?.(arg);
|
|
2409
|
+
}
|
|
2410
|
+
if (op === "delete_entry" || op === "delete" || op === "remove") {
|
|
2411
|
+
return getGroupMethod(shimMj, "admin", "deleteEntry")?.(arg);
|
|
2412
|
+
}
|
|
2413
|
+
if (op === "search_entries" || op === "search" || op === "find") {
|
|
2414
|
+
return getGroupMethod(shimMj, "search", "searchEntries")?.(arg);
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
return getGroupMethod(shimMj, "core", "createEntry")?.(arg);
|
|
2418
|
+
};
|
|
2419
|
+
}
|
|
2420
|
+
var DELEGATING_TOOL_MAPPINGS = [
|
|
2421
|
+
[
|
|
2422
|
+
[
|
|
2423
|
+
"search_entries",
|
|
2424
|
+
"searchEntries",
|
|
2425
|
+
"query_entries",
|
|
2426
|
+
"queryEntries",
|
|
2427
|
+
"mj_search_entries",
|
|
2428
|
+
"mjSearchEntries"
|
|
2429
|
+
],
|
|
2430
|
+
"search",
|
|
2431
|
+
"searchEntries"
|
|
2432
|
+
],
|
|
2433
|
+
[
|
|
2434
|
+
["get_recent_entries", "getRecentEntries", "mj_get_recent_entries", "mjGetRecentEntries"],
|
|
2435
|
+
"core",
|
|
2436
|
+
"getRecentEntries"
|
|
2437
|
+
],
|
|
2438
|
+
[
|
|
2439
|
+
["get_entry_by_id", "getEntryById", "mj_get_entry_by_id", "mjGetEntryById"],
|
|
2440
|
+
"core",
|
|
2441
|
+
"getEntryById"
|
|
2442
|
+
],
|
|
2443
|
+
[
|
|
2444
|
+
["list_projects", "listProjects", "mj_list_projects", "mjListProjects"],
|
|
2445
|
+
"admin",
|
|
2446
|
+
"listProjects"
|
|
2447
|
+
],
|
|
2448
|
+
[["get_project", "getProject", "mj_get_project", "mjGetProject"], "admin", "getProject"],
|
|
2449
|
+
[["list_tags", "listTags", "mj_list_tags", "mjListTags"], "core", "listTags"],
|
|
2450
|
+
[
|
|
2451
|
+
[
|
|
2452
|
+
"sqlite_journal_add_entry",
|
|
2453
|
+
"mj_create_entry",
|
|
2454
|
+
"mjCreateEntry",
|
|
2455
|
+
"create_entry",
|
|
2456
|
+
"createEntry",
|
|
2457
|
+
"insert_entry",
|
|
2458
|
+
"insertEntry",
|
|
2459
|
+
"add_entry",
|
|
2460
|
+
"addEntry",
|
|
2461
|
+
"new_entry",
|
|
2462
|
+
"newEntry",
|
|
2463
|
+
"log_entry",
|
|
2464
|
+
"logEntry",
|
|
2465
|
+
"save_entry",
|
|
2466
|
+
"saveEntry",
|
|
2467
|
+
"write_entry",
|
|
2468
|
+
"writeEntry"
|
|
2469
|
+
],
|
|
2470
|
+
"core",
|
|
2471
|
+
"createEntry"
|
|
2472
|
+
],
|
|
2473
|
+
[
|
|
2474
|
+
["mj_update_entry", "mjUpdateEntry", "update_entry", "updateEntry"],
|
|
2475
|
+
"admin",
|
|
2476
|
+
"updateEntry"
|
|
2477
|
+
],
|
|
2478
|
+
[
|
|
2479
|
+
["mj_delete_entry", "mjDeleteEntry", "delete_entry", "deleteEntry"],
|
|
2480
|
+
"admin",
|
|
2481
|
+
"deleteEntry"
|
|
2482
|
+
]
|
|
2483
|
+
];
|
|
2484
|
+
var DIRECT_CREATE_ENTRY_SHIMS = [
|
|
2485
|
+
"append",
|
|
2486
|
+
"append_entry",
|
|
2487
|
+
"appendEntry",
|
|
2488
|
+
"logJournal",
|
|
2489
|
+
"log_journal",
|
|
2490
|
+
"insertJournal",
|
|
2491
|
+
"insert_journal",
|
|
2492
|
+
"addJournal",
|
|
2493
|
+
"add_journal",
|
|
2494
|
+
"recordJournal",
|
|
2495
|
+
"record_journal",
|
|
2496
|
+
"appendJournal",
|
|
2497
|
+
"append_journal",
|
|
2498
|
+
"saveJournalEntry",
|
|
2499
|
+
"save_journal_entry",
|
|
2500
|
+
"addJournalEntry",
|
|
2501
|
+
"add_journal_entry",
|
|
2502
|
+
"createJournalEntry",
|
|
2503
|
+
"writeJournal"
|
|
2504
|
+
];
|
|
2505
|
+
function buildSandboxGlobals(options) {
|
|
2506
|
+
const { mjApi, shimMj, safeFsShim, frozenContext, executeCodeFn, updateMemoryFn, activeTimers } = options;
|
|
2507
|
+
const registerTimer = (handle) => {
|
|
2508
|
+
activeTimers?.add(handle);
|
|
2509
|
+
return handle;
|
|
2510
|
+
};
|
|
2511
|
+
const servicesProxy = new Proxy({}, { get: () => shimMj });
|
|
2512
|
+
const kernelProxy = new Proxy({}, { get: () => shimMj });
|
|
2513
|
+
const callableShim = () => createCallableShim(shimMj);
|
|
2514
|
+
const schemaShim = createSchemaShim(shimMj);
|
|
2515
|
+
const getSchemaShim = () => createSchemaShim(shimMj);
|
|
2516
|
+
const processOpFn = createProcessOperationFn(shimMj);
|
|
2517
|
+
const directCreateFn = (arg) => getGroupMethod(shimMj, "core", "createEntry")?.(arg);
|
|
2518
|
+
const updateConfigFn = (arg) => (getGroupMethod(shimMj, "admin", "update_configuration") ?? getGroupMethod(shimMj, "admin", "updateConfiguration"))?.(arg);
|
|
2519
|
+
const saveMemoryFn = (arg) => arg !== void 0 && arg !== null ? updateMemoryFn(arg) : Promise.resolve({ success: true });
|
|
2520
|
+
const sandbox = {
|
|
2521
|
+
mj: shimMj,
|
|
2522
|
+
mcp: shimMj,
|
|
2523
|
+
__mcp: shimMj,
|
|
2524
|
+
__mcp_server: shimMj,
|
|
2525
|
+
__mcp_client: shimMj,
|
|
2526
|
+
execute: executeCodeFn,
|
|
2527
|
+
mj_execute_code: executeCodeFn,
|
|
2528
|
+
execute_code: executeCodeFn,
|
|
2529
|
+
executeCode: executeCodeFn,
|
|
2530
|
+
mjExecuteCode: executeCodeFn,
|
|
2531
|
+
core: shimMj,
|
|
2532
|
+
journal: shimMj,
|
|
2533
|
+
_journal: shimMj,
|
|
2534
|
+
MJ: callableShim(),
|
|
2535
|
+
M: callableShim(),
|
|
2536
|
+
adapter: callableShim(),
|
|
2537
|
+
Entry: callableShim(),
|
|
2538
|
+
getJournal: () => Promise.resolve(shimMj),
|
|
2539
|
+
services: servicesProxy,
|
|
2540
|
+
kernel: kernelProxy,
|
|
2541
|
+
sqlite: shimMj,
|
|
2542
|
+
sqlite3: callableShim(),
|
|
2543
|
+
Database: callableShim(),
|
|
2544
|
+
better_sqlite3: callableShim(),
|
|
2545
|
+
betterSqlite3: callableShim(),
|
|
2546
|
+
BetterSqlite3: callableShim(),
|
|
2547
|
+
Sqlite3: callableShim(),
|
|
2548
|
+
cp: shimMj,
|
|
2549
|
+
child_process: shimMj,
|
|
2550
|
+
fs: safeFsShim,
|
|
2551
|
+
__safeFs: safeFsShim,
|
|
2552
|
+
safeFs: safeFsShim,
|
|
2553
|
+
path: pathShim,
|
|
2554
|
+
__path: pathShim,
|
|
2555
|
+
os: shimMj,
|
|
2556
|
+
util: shimMj,
|
|
2557
|
+
crypto: shimMj,
|
|
2558
|
+
buffer: shimMj,
|
|
2559
|
+
execSync: (..._args) => "",
|
|
2560
|
+
spawnSync: () => ({ status: 0, stdout: "", stderr: "", output: ["", "", ""] }),
|
|
2561
|
+
exec: (_cmd, cb) => {
|
|
2562
|
+
if (typeof cb === "function") {
|
|
2563
|
+
try {
|
|
2564
|
+
;
|
|
2565
|
+
cb(null, "", "");
|
|
2566
|
+
} catch {
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
},
|
|
2570
|
+
spawn: () => {
|
|
2571
|
+
const noop = () => {
|
|
2572
|
+
};
|
|
2573
|
+
return { on: noop, stdout: { on: noop }, stderr: { on: noop } };
|
|
2574
|
+
},
|
|
2575
|
+
postgres: shimMj,
|
|
2576
|
+
mysql: shimMj,
|
|
2577
|
+
db: shimMj,
|
|
2578
|
+
api: shimMj,
|
|
2579
|
+
memory: shimMj,
|
|
2580
|
+
mcpx: shimMj,
|
|
2581
|
+
memoryJournal: callableShim(),
|
|
2582
|
+
MemoryJournal: callableShim(),
|
|
2583
|
+
memory_journal: callableShim(),
|
|
2584
|
+
memory_journal_mcp: callableShim(),
|
|
2585
|
+
m: shimMj,
|
|
2586
|
+
env: shimMj,
|
|
2587
|
+
agent: shimMj,
|
|
2588
|
+
tools: shimMj,
|
|
2589
|
+
sdk: shimMj,
|
|
2590
|
+
client: shimMj,
|
|
2591
|
+
system: shimMj,
|
|
2592
|
+
projects: shimMj["projects"],
|
|
2593
|
+
tags: shimMj["tags"],
|
|
2594
|
+
utils: shimMj,
|
|
2595
|
+
sql: shimMj,
|
|
2596
|
+
schema: schemaShim,
|
|
2597
|
+
Schema: callableShim(),
|
|
2598
|
+
getSchema: getSchemaShim,
|
|
2599
|
+
get_schema: getSchemaShim,
|
|
2600
|
+
tables: schemaShim,
|
|
2601
|
+
Tables: callableShim(),
|
|
2602
|
+
getTables: getSchemaShim,
|
|
2603
|
+
get_tables: getSchemaShim,
|
|
2604
|
+
getInstance: () => shimMj,
|
|
2605
|
+
get_instance: () => shimMj,
|
|
2606
|
+
getClient: () => shimMj,
|
|
2607
|
+
get_client: () => shimMj,
|
|
2608
|
+
createClient: () => shimMj,
|
|
2609
|
+
create_client: () => shimMj,
|
|
2610
|
+
createInstance: () => shimMj,
|
|
2611
|
+
create_instance: () => shimMj,
|
|
2612
|
+
initClient: () => shimMj,
|
|
2613
|
+
init_client: () => shimMj,
|
|
2614
|
+
getDb: () => shimMj,
|
|
2615
|
+
get_db: () => shimMj,
|
|
2616
|
+
getDatabase: () => shimMj,
|
|
2617
|
+
get_database: () => shimMj,
|
|
2618
|
+
connectToDatabase: () => shimMj,
|
|
2619
|
+
openDatabase: () => shimMj,
|
|
2620
|
+
open_database: () => shimMj,
|
|
2621
|
+
prepare: (sql) => createPreparedStatementShim(typeof sql === "string" ? sql : "", shimMj),
|
|
2622
|
+
process_operation: processOpFn,
|
|
2623
|
+
processOperation: processOpFn,
|
|
2624
|
+
updateMemory: updateMemoryFn,
|
|
2625
|
+
update_memory: updateMemoryFn,
|
|
2626
|
+
setMemory: updateMemoryFn,
|
|
2627
|
+
set_memory: updateMemoryFn,
|
|
2628
|
+
updateJournal: updateMemoryFn,
|
|
2629
|
+
update_journal: updateMemoryFn,
|
|
2630
|
+
addMemory: updateMemoryFn,
|
|
2631
|
+
add_memory: updateMemoryFn,
|
|
2632
|
+
recordMemory: updateMemoryFn,
|
|
2633
|
+
record_memory: updateMemoryFn,
|
|
2634
|
+
createMemory: updateMemoryFn,
|
|
2635
|
+
create_memory: updateMemoryFn,
|
|
2636
|
+
loadJournal: () => Promise.resolve(shimMj),
|
|
2637
|
+
saveJournal: () => Promise.resolve({ success: true }),
|
|
2638
|
+
readJournal: () => getGroupMethod(shimMj, "core", "getRecentEntries")?.({ limit: 50 }),
|
|
2639
|
+
loadMemory: () => Promise.resolve(shimMj),
|
|
2640
|
+
saveMemory: saveMemoryFn,
|
|
2641
|
+
save_memory: saveMemoryFn,
|
|
2642
|
+
update_configuration: updateConfigFn,
|
|
2643
|
+
updateConfiguration: updateConfigFn,
|
|
2644
|
+
context: frozenContext,
|
|
2645
|
+
console: consoleShim,
|
|
2646
|
+
fetch: (..._args) => {
|
|
2647
|
+
const errObj = {
|
|
2648
|
+
success: false,
|
|
2649
|
+
error: `\u{1F6E0}\uFE0F AUTONOMOUS HEALING: Direct HTTP 'fetch()' is disabled in sandboxed Code Mode. To query metrics or system state, use mj.analytics.* or mj.admin.* tools (e.g. mj.analytics.getStatistics()).`,
|
|
2650
|
+
code: "VALIDATION_ERROR",
|
|
2651
|
+
category: "validation",
|
|
2652
|
+
recoverable: true
|
|
2653
|
+
};
|
|
2654
|
+
return Promise.resolve({
|
|
2655
|
+
...errObj,
|
|
2656
|
+
json: () => Promise.resolve(errObj),
|
|
2657
|
+
text: () => Promise.resolve(JSON.stringify(errObj)),
|
|
2658
|
+
ok: false,
|
|
2659
|
+
status: 403
|
|
2660
|
+
});
|
|
2661
|
+
},
|
|
2662
|
+
sleep: (ms) => new Promise((resolve) => {
|
|
2663
|
+
registerTimer(setTimeout(resolve, Math.min(Math.max(0, ms), 3e4)));
|
|
2664
|
+
}),
|
|
2665
|
+
setTimeout: (cb, ms, ...args) => registerTimer(setTimeout(cb, Math.min(Math.max(0, ms), 3e4), ...args)),
|
|
2666
|
+
setInterval: void 0,
|
|
2667
|
+
setImmediate: void 0,
|
|
2668
|
+
getConfig: () => Promise.resolve({ dbPath: "memory-journal.db" }),
|
|
2669
|
+
process: Object.freeze({
|
|
2670
|
+
exit: (code) => ({
|
|
2671
|
+
success: (code ?? 0) === 0,
|
|
2672
|
+
exited: true,
|
|
2673
|
+
exitCode: code ?? 0
|
|
2674
|
+
}),
|
|
2675
|
+
env: Object.freeze({})
|
|
2676
|
+
}),
|
|
2677
|
+
require: void 0,
|
|
2678
|
+
__dirname: void 0,
|
|
2679
|
+
__filename: void 0,
|
|
2680
|
+
global: void 0,
|
|
2681
|
+
globalThis: shimMj,
|
|
2682
|
+
Proxy: void 0
|
|
2683
|
+
};
|
|
2684
|
+
for (const [aliases, group, method] of DELEGATING_TOOL_MAPPINGS) {
|
|
2685
|
+
const delegated = makeDelegatingTool(shimMj, group, method);
|
|
2686
|
+
for (const alias of aliases) {
|
|
2687
|
+
sandbox[alias] = delegated;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
for (const name of DIRECT_CREATE_ENTRY_SHIMS) {
|
|
2691
|
+
sandbox[name] = directCreateFn;
|
|
2692
|
+
}
|
|
2693
|
+
for (const key of Object.keys(mjApi)) {
|
|
2694
|
+
const val = mjApi[key];
|
|
2695
|
+
if (val !== null && typeof val === "object" || typeof val === "function") {
|
|
2696
|
+
for (const groupMethod of Object.keys(val)) {
|
|
2697
|
+
if (groupMethod in sandbox) continue;
|
|
2698
|
+
const fn = Reflect.get(val, groupMethod);
|
|
2699
|
+
if (typeof fn === "function") {
|
|
2700
|
+
sandbox[groupMethod] = fn;
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
if (typeof val === "function" && !(key in sandbox)) {
|
|
2704
|
+
sandbox[key] = val;
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
return Object.freeze(sandbox);
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
// src/codemode/worker/result-compactor.ts
|
|
2712
|
+
function compactOversizedResult(val, limitBytes, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
|
|
2713
|
+
if (val === null || val === void 0 || typeof val !== "object") {
|
|
2714
|
+
return val;
|
|
2715
|
+
}
|
|
2716
|
+
if (depth > 6) {
|
|
2717
|
+
return "[MaxDepthExceeded]";
|
|
2718
|
+
}
|
|
2719
|
+
if (seen.has(val)) {
|
|
2720
|
+
return "[Circular]";
|
|
2721
|
+
}
|
|
2722
|
+
seen.add(val);
|
|
2723
|
+
if (Array.isArray(val)) {
|
|
2724
|
+
const arr = val;
|
|
2725
|
+
const maxItems = arr.length > 25 ? 20 : arr.length;
|
|
2726
|
+
const compactedArr = [];
|
|
2727
|
+
for (let i = 0; i < maxItems; i++) {
|
|
2728
|
+
const item = arr[i];
|
|
2729
|
+
if (typeof item === "string" && item.length > 400) {
|
|
2730
|
+
compactedArr.push(
|
|
2731
|
+
`${item.slice(0, 300)}... [truncated by Code Mode result size guardrail]`
|
|
2732
|
+
);
|
|
2733
|
+
} else {
|
|
2734
|
+
compactedArr.push(compactOversizedResult(item, limitBytes, depth + 1, seen));
|
|
2735
|
+
}
|
|
2736
|
+
}
|
|
2737
|
+
if (arr.length > maxItems) {
|
|
2738
|
+
compactedArr.push({
|
|
2739
|
+
_truncated: true,
|
|
2740
|
+
omitted_items_count: arr.length - maxItems,
|
|
2741
|
+
message: `\u26A0\uFE0F Array truncated from ${arr.length} to ${maxItems} items to fit within ${Math.round(limitBytes / 1024)}KB egress boundary. Pass 'max_result_size' parameter in mj_execute_code to retrieve full data.`
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
return compactedArr;
|
|
2745
|
+
}
|
|
2746
|
+
const compactedObj = {};
|
|
2747
|
+
const entries = Object.entries(val);
|
|
2748
|
+
const maxKeys = entries.length > 100 ? 100 : entries.length;
|
|
2749
|
+
for (let i = 0; i < maxKeys; i++) {
|
|
2750
|
+
const entry = entries[i];
|
|
2751
|
+
if (!entry) continue;
|
|
2752
|
+
const [k, v] = entry;
|
|
2753
|
+
if (typeof v === "string") {
|
|
2754
|
+
if (v.length > 400) {
|
|
2755
|
+
compactedObj[k] = `${v.slice(0, 300)}... [truncated by Code Mode result size guardrail]`;
|
|
2756
|
+
} else {
|
|
2757
|
+
compactedObj[k] = v;
|
|
2758
|
+
}
|
|
2759
|
+
} else if (typeof v === "object" && v !== null) {
|
|
2760
|
+
compactedObj[k] = compactOversizedResult(v, limitBytes, depth + 1, seen);
|
|
2761
|
+
} else {
|
|
2762
|
+
compactedObj[k] = v;
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
if (entries.length > maxKeys) {
|
|
2766
|
+
compactedObj["_omitted_keys_count"] = entries.length - maxKeys;
|
|
2767
|
+
}
|
|
2768
|
+
if (depth === 0) {
|
|
2769
|
+
compactedObj["_compaction_notice"] = `\u26A0\uFE0F Result payload was automatically compacted because serialized payload exceeded the ${Math.round(limitBytes / 1024)}KB boundary. Pass 'max_result_size' in mj_execute_code (e.g. max_result_size: ${limitBytes * 2}) to retrieve full contents without truncation.`;
|
|
2770
|
+
}
|
|
2771
|
+
return compactedObj;
|
|
2772
|
+
}
|
|
2773
|
+
function serializeAndEnforceEgress(result, maxResultSize) {
|
|
2774
|
+
if (!result.success) return;
|
|
2775
|
+
const egressLimit = maxResultSize ?? 100 * 1024;
|
|
2776
|
+
try {
|
|
2777
|
+
let bytes = 0;
|
|
2778
|
+
const cache = /* @__PURE__ */ new Set();
|
|
2779
|
+
const resultJson = JSON.stringify(result.result, (_key, value) => {
|
|
2780
|
+
if (typeof value === "object" && value !== null) {
|
|
2781
|
+
if (cache.has(value)) return "[Circular]";
|
|
2782
|
+
cache.add(value);
|
|
2783
|
+
bytes += 5;
|
|
2784
|
+
} else if (typeof value === "string") {
|
|
2785
|
+
bytes += value.length + 2;
|
|
2786
|
+
} else if (typeof value === "number" || typeof value === "boolean") {
|
|
2787
|
+
bytes += 8;
|
|
2788
|
+
} else if (typeof value === "bigint") {
|
|
2789
|
+
const str = value.toString();
|
|
2790
|
+
bytes += str.length + 2;
|
|
2791
|
+
return str;
|
|
2792
|
+
} else {
|
|
2793
|
+
bytes += 5;
|
|
2794
|
+
}
|
|
2795
|
+
if (bytes > egressLimit) {
|
|
2796
|
+
throw new Error(`EgressLimitExceeded:${bytes}`);
|
|
2797
|
+
}
|
|
2798
|
+
return value;
|
|
2799
|
+
});
|
|
2800
|
+
if (resultJson !== void 0) {
|
|
2801
|
+
const byteLength = Buffer.byteLength(resultJson, "utf8");
|
|
2802
|
+
if (byteLength > egressLimit) {
|
|
2803
|
+
throw new Error(`EgressLimitExceeded:${byteLength}`);
|
|
2804
|
+
}
|
|
2805
|
+
result.result = JSON.parse(resultJson);
|
|
2806
|
+
} else {
|
|
2807
|
+
result.result = void 0;
|
|
2808
|
+
}
|
|
2809
|
+
} catch (err) {
|
|
2810
|
+
if (err instanceof Error && err.message.startsWith("EgressLimitExceeded:")) {
|
|
2811
|
+
const actualBytesStr = err.message.split(":")[1];
|
|
2812
|
+
const actualBytes = actualBytesStr !== void 0 ? Number(actualBytesStr) : egressLimit + 1;
|
|
2813
|
+
const actualKb = (actualBytes / 1024).toFixed(1);
|
|
2814
|
+
let compactedSuccessfully = false;
|
|
2815
|
+
if (result.result !== null && typeof result.result === "object") {
|
|
2816
|
+
try {
|
|
2817
|
+
const compacted = compactOversizedResult(result.result, egressLimit);
|
|
2818
|
+
if (compacted !== void 0) {
|
|
2819
|
+
const compactedJson = JSON.stringify(compacted);
|
|
2820
|
+
const compactedBytes = Buffer.byteLength(compactedJson, "utf8");
|
|
2821
|
+
if (compactedBytes <= egressLimit) {
|
|
2822
|
+
result.result = JSON.parse(compactedJson);
|
|
2823
|
+
result.success = true;
|
|
2824
|
+
delete result.error;
|
|
2825
|
+
compactedSuccessfully = true;
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
} catch {
|
|
2829
|
+
compactedSuccessfully = false;
|
|
2830
|
+
}
|
|
2831
|
+
}
|
|
2832
|
+
if (!compactedSuccessfully) {
|
|
2833
|
+
result.success = false;
|
|
2834
|
+
result.error = `\u{1F6E0}\uFE0F AUTONOMOUS HEALING: Output limit exceeded: Result serialization exceeded the ${Math.round(egressLimit / 1024)}KB boundary (Actual size: >${actualKb}KB). Please aggregate or filter your results to reduce the payload size, or pass 'max_result_size' parameter (in bytes) to accommodate larger payloads.`;
|
|
2835
|
+
result.result = void 0;
|
|
2836
|
+
}
|
|
2837
|
+
} else {
|
|
2838
|
+
result.success = false;
|
|
2839
|
+
result.error = `Result could not be serialized or exceeded memory limits: ${err instanceof Error ? err.message : String(err)}`;
|
|
2840
|
+
result.result = void 0;
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
// src/codemode/worker-script.ts
|
|
2846
|
+
hardenOuterFunctionPrototypes();
|
|
2847
|
+
process.on("unhandledRejection", () => {
|
|
2848
|
+
});
|
|
2849
|
+
process.on("uncaughtException", () => {
|
|
2850
|
+
});
|
|
2851
|
+
var rpcPort = null;
|
|
2852
|
+
var rpcIdCounter = 0;
|
|
2853
|
+
var pendingRpcRequests = /* @__PURE__ */ new Map();
|
|
2854
|
+
function rpcCall(group, method, args) {
|
|
2855
|
+
return new Promise((resolve, reject) => {
|
|
2856
|
+
if (!rpcPort) {
|
|
2857
|
+
reject(new Error("RPC port not initialized"));
|
|
2858
|
+
return;
|
|
2859
|
+
}
|
|
2860
|
+
const id = ++rpcIdCounter;
|
|
2861
|
+
pendingRpcRequests.set(id, { resolve, reject });
|
|
2862
|
+
const request = { id, group, method, args };
|
|
2863
|
+
rpcPort.postMessage(request);
|
|
2864
|
+
});
|
|
2865
|
+
}
|
|
2866
|
+
async function executeCode(code, methodList, schemaList, timeoutMs, contextObj, readonlyMode) {
|
|
2867
|
+
const startCpu = process.cpuUsage();
|
|
2868
|
+
const startTime = performance.now();
|
|
2869
|
+
const activeTimers = /* @__PURE__ */ new Set();
|
|
2870
|
+
try {
|
|
2871
|
+
const mjApi = buildApiProxy(rpcCall, methodList, schemaList, readonlyMode, contextObj);
|
|
2872
|
+
for (const key of Object.keys(mjApi)) {
|
|
2873
|
+
const val = mjApi[key];
|
|
2874
|
+
if (typeof val === "object" && val !== null) Object.freeze(val);
|
|
2875
|
+
}
|
|
2876
|
+
Object.freeze(mjApi);
|
|
2877
|
+
const safeFsShim = createSafeFsShim(contextObj);
|
|
2878
|
+
const executeCodeFnRef = {};
|
|
2879
|
+
const updateMemoryFnHolder = {};
|
|
2880
|
+
const shimMj = createShimMjProxy({
|
|
2881
|
+
mjApi,
|
|
2882
|
+
safeFsShim,
|
|
2883
|
+
executeCodeFnRef,
|
|
2884
|
+
getUpdateMemoryFn: () => updateMemoryFnHolder.current ?? (() => void 0)
|
|
2885
|
+
});
|
|
2886
|
+
const updateMemoryFn = createUpdateMemoryFn(shimMj);
|
|
2887
|
+
updateMemoryFnHolder.current = updateMemoryFn;
|
|
2888
|
+
const frozenContext = createContextProxy(contextObj);
|
|
2889
|
+
const vmContextRef = {};
|
|
2890
|
+
const invokeCreateEntry = (payload) => {
|
|
2891
|
+
const coreGroup = shimMj["core"];
|
|
2892
|
+
if (typeof coreGroup === "object" && coreGroup !== null || typeof coreGroup === "function") {
|
|
2893
|
+
const fn = Reflect.get(coreGroup, "createEntry");
|
|
2894
|
+
if (typeof fn === "function") return fn(payload);
|
|
2895
|
+
}
|
|
2896
|
+
return void 0;
|
|
2897
|
+
};
|
|
2898
|
+
const executeCodeFn = async (arg) => {
|
|
2899
|
+
let codeToExec = "";
|
|
2900
|
+
if (typeof arg === "string") {
|
|
2901
|
+
codeToExec = arg;
|
|
2902
|
+
} else if (typeof arg === "object" && arg !== null && !Array.isArray(arg)) {
|
|
2903
|
+
const codeProp = Reflect.get(arg, "code");
|
|
2904
|
+
const scriptProp = Reflect.get(arg, "script");
|
|
2905
|
+
codeToExec = typeof codeProp === "string" ? codeProp : typeof scriptProp === "string" ? scriptProp : "";
|
|
2906
|
+
if (codeToExec === "" && (typeof Reflect.get(arg, "content") === "string" || typeof Reflect.get(arg, "text") === "string" || typeof Reflect.get(arg, "description") === "string" || typeof Reflect.get(arg, "title") === "string")) {
|
|
2907
|
+
return invokeCreateEntry(arg);
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
if (codeToExec !== "") {
|
|
2911
|
+
const trimmed = codeToExec.trim();
|
|
2912
|
+
const isNaturalPrompt = /^(?:write|document|create|include|record|summary|log|add|added|note|task|fix|implement)\b/i.test(trimmed) && !/\b(const|let|var|function|return|await|import|export)\b/.test(trimmed);
|
|
2913
|
+
if (isNaturalPrompt || /^(?:create|add|new|record|log)?\s*entry\b/i.test(trimmed)) {
|
|
2914
|
+
const firstLine = (trimmed.split("\n")[0] ?? "").replace(/^(?:create|add|new|record|log|insert)?\s*entry\s*(?:for|:)?\s*/i, "").replace(/[:.]+$/, "").trim();
|
|
2915
|
+
const title = firstLine.length > 0 && firstLine.length < 80 ? firstLine : "Journal Entry";
|
|
2916
|
+
return invokeCreateEntry({ title, content: trimmed, entry_type: "technical_decision" });
|
|
2917
|
+
}
|
|
2918
|
+
if (vmContextRef.current !== void 0) {
|
|
2919
|
+
const transformed2 = transformAutoReturn(codeToExec);
|
|
2920
|
+
const wrapped = `(async () => {
|
|
2921
|
+
${transformed2}
|
|
2922
|
+
})()`;
|
|
2923
|
+
return await vm2.runInContext(wrapped, vmContextRef.current, { timeout: timeoutMs });
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
return { success: true };
|
|
2927
|
+
};
|
|
2928
|
+
executeCodeFnRef.current = executeCodeFn;
|
|
2929
|
+
const sandbox = buildSandboxGlobals({
|
|
2930
|
+
mjApi,
|
|
2931
|
+
shimMj,
|
|
2932
|
+
safeFsShim,
|
|
2933
|
+
frozenContext,
|
|
2934
|
+
executeCodeFn,
|
|
2935
|
+
updateMemoryFn,
|
|
2936
|
+
activeTimers
|
|
2937
|
+
});
|
|
2938
|
+
const context = vm2.createContext(sandbox, {
|
|
2939
|
+
name: "codemode-worker-sandbox",
|
|
2940
|
+
codeGeneration: { strings: false, wasm: false }
|
|
2941
|
+
});
|
|
2942
|
+
vmContextRef.current = context;
|
|
2943
|
+
freezeInnerVmContext(context);
|
|
2944
|
+
const transformed = transformAutoReturn(code);
|
|
2945
|
+
const script = new vm2.Script(`(async () => {
|
|
2946
|
+
${transformed}
|
|
2947
|
+
})()`, {
|
|
2948
|
+
filename: "codemode-execution.js"
|
|
2949
|
+
});
|
|
2950
|
+
const resultPromise = script.runInContext(context, { timeout: timeoutMs });
|
|
2951
|
+
const result = await resultPromise;
|
|
2952
|
+
const endTime = performance.now();
|
|
2953
|
+
const endCpu = process.cpuUsage(startCpu);
|
|
2954
|
+
const metrics = {
|
|
2955
|
+
wallTimeMs: Math.round(endTime - startTime),
|
|
2956
|
+
cpuTimeMs: Math.round((endCpu.user + endCpu.system) / 1e3),
|
|
2957
|
+
memoryUsedMb: 0
|
|
2958
|
+
};
|
|
2959
|
+
return { success: true, result, metrics };
|
|
2960
|
+
} catch (err) {
|
|
2961
|
+
const endTime = performance.now();
|
|
2962
|
+
const endCpu = process.cpuUsage(startCpu);
|
|
2963
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
2964
|
+
const errString = String(err);
|
|
2965
|
+
if (errString.includes("missing ) after argument list") || errString.includes("is not a function") || errString.includes("Invalid or unexpected token") || errString.includes("Unexpected token") || errString.includes("Unexpected identifier") || errString.includes("Cannot use import statement")) {
|
|
2966
|
+
error.message = `\u{1F6E0}\uFE0F AUTONOMOUS HEALING: Syntax error in Code Mode execution (${error.message}). Code Mode requires valid JavaScript code (e.g., 'return await mj.core.getRecentEntries({ limit: 10 })' or 'return await mj.core.createEntry(...)'), not raw SQL statements or unquoted text.
|
|
2967
|
+
|
|
2968
|
+
\u{1F4A1} Tip: When querying the journal, use Code Mode methods like 'return await mj.core.getRecentEntries({ limit: 10 })' or 'return await mj.search.searchEntries({ query: "..." })'. When passing long multi-line strings or markdown with embedded quotes/backticks, pass them safely via the \`context\` parameter and reference them as \`context.myParam\`.`;
|
|
2969
|
+
}
|
|
2970
|
+
return {
|
|
2971
|
+
success: false,
|
|
2972
|
+
error: error.message,
|
|
2973
|
+
metrics: {
|
|
2974
|
+
wallTimeMs: Math.round(endTime - startTime),
|
|
2975
|
+
cpuTimeMs: Math.round((endCpu.user + endCpu.system) / 1e3),
|
|
2976
|
+
memoryUsedMb: 0
|
|
2977
|
+
}
|
|
2978
|
+
};
|
|
2979
|
+
} finally {
|
|
2980
|
+
for (const handle of activeTimers) {
|
|
2981
|
+
clearTimeout(handle);
|
|
2982
|
+
}
|
|
2983
|
+
activeTimers.clear();
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
function isExecuteMessage(msg) {
|
|
2987
|
+
return msg !== null && msg !== void 0 && typeof msg === "object" && "type" in msg && Reflect.get(msg, "type") === "EXECUTE";
|
|
2988
|
+
}
|
|
2989
|
+
parentPort?.on("message", (msg) => {
|
|
2990
|
+
void (async () => {
|
|
2991
|
+
if (!isExecuteMessage(msg)) return;
|
|
2992
|
+
const { id, code, methodList, schemaList, timeoutMs, maxResultSize, rpcPort: newRpcPort, contextObj, readonlyMode } = msg;
|
|
2993
|
+
rpcPort = newRpcPort;
|
|
2994
|
+
rpcIdCounter = 0;
|
|
2995
|
+
pendingRpcRequests.clear();
|
|
2996
|
+
rpcPort?.on("message", (response) => {
|
|
2997
|
+
const pending = pendingRpcRequests.get(response.id);
|
|
2998
|
+
if (pending !== void 0) {
|
|
2999
|
+
pendingRpcRequests.delete(response.id);
|
|
3000
|
+
if (response.error !== void 0) pending.reject(new Error(response.error));
|
|
3001
|
+
else pending.resolve(response.result);
|
|
3002
|
+
}
|
|
3003
|
+
});
|
|
3004
|
+
const result = await executeCode(code, methodList, schemaList, timeoutMs ?? 3e4, contextObj, readonlyMode);
|
|
3005
|
+
serializeAndEnforceEgress(result, maxResultSize);
|
|
3006
|
+
rpcPort?.close();
|
|
3007
|
+
rpcPort = null;
|
|
3008
|
+
parentPort?.postMessage({ type: "RESULT", id, result });
|
|
414
3009
|
})();
|
|
415
3010
|
});
|